In the Emscripten wiki (Interacting with code), there are only two types listed as possible return types to be passed to ccall
or cwrap
("number" and "string"). How can I wrap / call a function which doesn't return anything (void return type)?
"null" works as a return type for void functions instead of a string.
For example:
my_fun = Module.cwrap('my_fun', null, ['number', 'number']);
Examples on the site also use number
, as it will just be ignored. This is what the example in the wiki uses.
I use this in all of my emscripted code, and it works great. In general, looking in the examples folder of the emscripten
repo is your best bet for syntax. Also, this is the documented use, so it may be safer to hedge against future changes.
For example, a C function
void test(char* buffer, int buffersize) {
// ...
}
could be wrapped as
var test = Module.cwrap('test', 'number', ['number', 'number']);
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