b-ccall-cwrap-and-direct-function-calls
B ccall, cwrap, and direct function calls
This appendix covers
- Calling a module’s function from JavaScript using the Emscripten helper functions ccall and cwrap
- Calling a module’s function directly from JavaScript without using the Emscripten helper functions
- Passing arrays to a function
When working with Emscripten’s generated JavaScript plumbing code you have a few options for calling into a module. The most common approach is by using the ccall or cwrap functions, which help with memory management when passing and returning strings for example. You can also call a module function directly.
B.1 ccall
The ccall function allows you to call a function in the WebAssembly module and receive the results. The ccall function accepts four parameters: