可以将C++中的函数指针(使用Emscripten编译成JavaScript)直接传递到手写的JS代码中吗?我已经找到了一些创建JavaScript函数的函数指针以传递给C++的方法,但没有一种方式可以在运行时将C++代码中的函数指针暴露给JavaScript。
整个代码中,我想要完成下面的代码片段,以便在我执行
整个代码中,我想要完成下面的代码片段,以便在我执行
console.log
时调用传递的函数cFunctionPointer
。void passToJs(void (*cFunctionPointer)()) {
EM_ASM_ARGS({
// Prints out an integer. Would like to be able to
// call the function it represents.
console.log($0);
}, cFunctionPointer);
}