Hello,
I am trying to get a JS function pointer using Module.Runtime.addFunction as specified in doc :
https://kripken.github.io/emscripten-site/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html#calling-javascript-functions-as-function-pointers-from-c
var pointer = Module.Runtime.addFunction(function(stateCode) {
console.log("State change ! " + stateCode);
});
Module.ccall('set_state_change_callback', 'number', ['number'], [pointer]);
I have added to emcc requested setting :
-s RESERVED_FUNCTION_POINTERS=10
But i still get a JS exception
TypeError: Module.Runtime is undefined
Usage exemple https://github.com/kripken/emscripten/blob/1.29.12/tests/test_core.py#L6237 does not help me to understand what is going wrong with my code.
Any hint and clarification please ? :)
Regards,
Harold
Looking in the generated code might help, to see why Module.Runtime doesn't exist - although I think we might just not export it by default on the Module object. But you should be able to access the Runtime object directly (no Module.), unless you built with an option like MODULARIZE (or, even with that option, if your handwritten code is in a pre- or post-js, as those are included with the code in the module).
Ok, my bad.
Runtime variable is well defined in generated code.
I just called Runtime.addFunction in a "script" tag after the "script async" tag including generated .js.
So my "script" tag is evaluated before that the "script async" has finished to load and therefore Runtime was not defined.
Using --post-js to include the code into the generated .js as you suggested solve the issue, thank you !
Regards,
Harold
For new people here from Google, the Runtime object was removed in v1.37.27. You just need to remove the Runtime. prefix.
See FAQ
Most helpful comment
For new people here from Google, the
Runtimeobject was removed in v1.37.27. You just need to remove theRuntime.prefix.See FAQ