I read https://developer.mozilla.org/en-US/docs/WebAssembly/Using_the_JavaScript_API and http://webassembly.org/docs/js/, and it seems all examples I've found for calling Javascript functions from wasm are written in the LISP-inspired syntax.
Is it possible to import JS functions in wasm using emscripten C?
Yes, Emscripten documents how to do this. The easiest thing is to declare the JS function as extern "C"
in C++. It'll be in your wasm module's exports, which you then need to pass in as an import.
As another example, the wasm waterfall build musl in JavaScript, and runs some GCC tests which it compiles to wasm. All C library functions are in JS, and wasm calls into JS for them. No magic: the C library functions are just declared as extern "C"
and then passed in as an import.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With