Call C++ Function Pointer From Javascript
Is it possible to pass function pointers from C++ (compiled into Javascript using Emscripten) to directly-written JS? I've found ways of creating function pointers of Javascript fu
Solution 1:
Found the answer at https://stackoverflow.com/a/25584986/1319998. You can use the Runtime.dynCall
function:
voidpassToJs(void (*cFunctionPointer)()) {
EM_ASM_ARGS({
Module.Runtime.dynCall('v', $0, []);
}, cFunctionPointer);
}
The 'v'
is the signature of a void function that doesn't take any arguments.
Apparently it supports other signatures, such as 'vii'
, which is a void function that takes 2 integer arguments. The integer arguments would then have to passed in the array which is the 3rd argument of Runtime.dynCall
.
Post a Comment for "Call C++ Function Pointer From Javascript"