Alb*_*dez 4 javascript emscripten
使用Emscripten,是否可以从JavaScript调用函数指针(因此,一个数字)?
函数的签名是可变的,所以我不能编写帮助程序并完成.
为了举例说明,我有一个这样的函数:
// Returns a function pointer to call, with the appropiate
// arguments, to initialize the demanded feature.
void* get_feature_activator(feature_t feat);
Run Code Online (Sandbox Code Playgroud)
您应该按如下方式使用它:
// Initialize the speaker
void* activator = get_feature_activator(FEATURE_SPEAKER);
// We know this function needs one float, so we cast and call it
((void(*)(float))activator) (3.0);
Run Code Online (Sandbox Code Playgroud)
要对JavaScript执行相同的操作:
var activator = _get_feature_activator(constants.FEATURE_SPEAKER);
// TODO: Need to call this pointer with one float
Run Code Online (Sandbox Code Playgroud)
小智 6
您可以使用JS从JS调用C函数指针Runtime.dynCall.例如,参见
争论是(type signature, pointer, array of arguments).例如,类型'vi'表示返回void,接收一个整数参数.这对应于您可以在生成的代码中看到的FUNCTION_TABLE_vi.
| 归档时间: |
|
| 查看次数: |
2379 次 |
| 最近记录: |