6

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?

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Please use commit IDs to create permanent links when referring to code in Github. Your Github links are already ruined. Here's a commit-id-based link to the relevant test demonstrating the --js-library flag github.com/kripken/emscripten/blob/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.