emscripten

Pass array to C function with emscripten

不打扰是莪最后的温柔 提交于 2019-12-11 00:25:11
问题 I think this question is similar to this one and I used most of it's answer for my problem, but I still have issues: First the C code: #include <stdio.h> extern "C" { void fillArray(int* a, int len) { for (int i = 0; i<len; i++) { a[i] = i*i; } for (int j = 0; j < len; ++j) { printf("a[%d] = %d\n", j, a[j]); } } } I'm passing a pointer to an array to my C function and fill it with some information. I compile this code with emcc -o writebmp.js dummyCode\cwrapCall.cxx -s EXPORTED_FUNCTIONS="['

Call C++ function pointer from Javascript

拟墨画扇 提交于 2019-12-10 21:39:34
问题 Is it possible to pass function pointers from C++ (compiled into Javascript using Emscripten) to directly-written JS? I've found ways of creating function pointers of Javascript functions to pass to C++, but not a way of exposing a function pointer, given a value at runtime in C++ code, to Javascript. Code-wide, what I'm after is to be able to complete the code snippet below in order to call the function passed as cFunctionPointer where I'm doing the console.log void passToJs(void (

Obtaining JavaScript import object entries from a WebAssembly .wasm module

痞子三分冷 提交于 2019-12-10 18:38:46
问题 I want to understand what a Rust program actually exports when it is compiled to a wasm file so I can provide a valid importObject to the instantiate function: WebAssembly.instantiate(bufferSource, importObject); As far as I understand, the only way to do this is by exporting an s-syntax like file of the compiled code. I can't find how to do this in their docs or through web searches. 回答1: You can use a tool such as wabt's wasm2wast to translate a .wasm file to the equivalent .wast . That

Calling a function pointer with Emscripten

主宰稳场 提交于 2019-12-10 17:08:59
问题 With Emscripten, is it possible to call a function pointer (thus, a number) from JavaScript? The signature of the function is variable, so I can't write a helper and be done. To illustrate an example, I've got a function like this: // Returns a function pointer to call, with the appropiate // arguments, to initialize the demanded feature. void* get_feature_activator(feature_t feat); You're supposed to use it as follows: // Initialize the speaker void* activator = get_feature_activator(FEATURE

CMake project for Emscripten

◇◆丶佛笑我妖孽 提交于 2019-12-10 06:15:21
问题 I want to make CMake and Emscripten friends. Didn't find more or less informative documentation on the Emscripten project website, but they provide CMake toolchain file so I think it should be possible. So far very basic compilation without advanced parameters works fine, but I have issues while using embind and preloading files. Linking process seems to miss Emscripten "binaries" and produces warnings for all embind related functions like this one: warning: unresolved symbol: _embind

Installing Emscripten on Ubuntu

怎甘沉沦 提交于 2019-12-10 02:23:43
问题 I am trying to install Emscripten on Ubuntu, but the official installation guide for Emscripten doesn't offer any instructions for installing Emscripten on Linux. The only advice that the installation guide has to offer is: If you are on Linux, things should be very simple for you and there is no need for any additional guide. I have read the README.md file in the Emscripten repository as well, and it doesn't offer any instructions for Ubuntu either. What steps will I need to follow in order

Where should I defined emscripten extern functions in JS?

主宰稳场 提交于 2019-12-08 09:19:45
问题 Suppose I have function x in C++ defined as: extern "C" void x(); and I implement it in JS in global context function _x() { console.log('x called'); } _x is defined in asm compiled js file, which is getting invoked and not my implementation. What am I doing wrong? I'm getting this warning while linking: warning: unresolved symbol: x Here is the stacktrace: Uncaught abort() at Error at jsStackTrace (http://localhost/module.js:978:13) at stackTrace (http://localhost/module.js:995:22) at abort

How can I pass an array from JavaScript to Rust that has been compiled with Emscripten?

Deadly 提交于 2019-12-07 19:30:04
问题 Below is my Rust and JavaScript code that I made based on an example that calls C code from JavaScript with an array and an example that calls Rust functions from JavaScript without parameters. display-array.rs #![feature(link_args)] #[link_args = "-s EXPORTED_FUNCTIONS=['_display_array']"] extern {} #[no_mangle] pub fn display_array(array: &[f32]) { println!("Rust - array size: {}", array.len()); println!("Rust - array: {:?}", array); } fn main() { /* Intentionally left blank */ }

How to bridge a JavaScript (ragged) array and an std::vector<std::vector<T>> object?

好久不见. 提交于 2019-12-07 15:17:18
问题 In JavaScript I have a list of "lines", each of which consists of indefinite number of "points", each of which has a form of [x, y] . So it is a 3D ragged array. Now I need to pass it to my C++ code with the help from emscripten (embind). Here's declaration of the C++ function: Eigen::MatrixXd f(const std::vector<std::vector<std::vector<double>>>& lines); And I would like to get a list of lists ( [[m11, m12],[m22, m22],...] ) in JavaScript after calling f . How to write the binding code in

WebAssembly calling JavaScript methods from wasm i.e. within C++ code

折月煮酒 提交于 2019-12-07 07:51:44
问题 I was playing with WebAssembly and so far and I was able to manage emscripten compile my test C++ project to wasm file em++ provides me 2 files i.e. mainTest.js mainTest.wasm When I load mainTest.js in my html page then I get a JavaScript object called " Module ". I did found how to call C++/wasm methods from javascript i.e. something like: var myTestInteger = Module._callMyTestMethod(); and read strings from the Module.wasmMemory.buffer , but I do NOT understand how to call JavaScript from C