Calling A Function Pointer With Emscripten
With Emscripten, is it possible to call a function pointer (thus, a number) from JavaScript? The signature of the function is variable, so I can't write a helper and be done. To il
Solution 1:
You can call a C function pointer from JS using Runtime.dynCall. See for example
The arguments are (type signature, pointer, array of arguments). For example, the type 'vi' means return void, receive one integer parameter. This corresponds to FUNCTION_TABLE_vi which you can see in the generated code.
Solution 2:
I would create a C function:
voidcall_feature_activator(int activator, float in_val) {
((void(*)(float))activator) (in_val);
}
You can then call the function on the JavaScript side to trigger your activator call and it will handle casting back to a function pointer and calling it.
Post a Comment for "Calling A Function Pointer With Emscripten"