Is there a way to access function pointers living inside the WebAssembly module?
For example, given the following “module” compiled into WebAssembly:
extern void set_callback(void (*callback)(void *arg), void *arg);
static void callback(void *arg)
{
}
int main() {
set_callback(&callback, 0);
return 0;
}
Can a do_callbackJavaScript implementation call a callback without having to rely on exporting the intermediate C function to make the actual function call?
var instance = new WebAssembly.Instance(module, {
memory:
env: {
set_callback: function set_callback(callbackptr, argptr) {
},
},
});
By exporting an intermediate function, I mean that I could add an internal function with public visibility.
do_callback(void (*callback)(void *arg), void *arg)
{
callback();
}
Then the JavaScript function set_callbackcan call the function pointer through the delegate function do_callback.
function set_callback(callbackptr, argptr) {
instance.exports.do_callback(callbackptr, argptr);
}
But, it is preferable to do this without missing this explicit indirect relation, is this possible using function tables?