您当前的位置: 首页 >  ar

phymat.nico

暂无认证

  • 2浏览

    0关注

    1967博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

abort(Assertion failed: Missing signature argument to addFunction)

phymat.nico 发布时间:2020-07-02 15:38:54 ,浏览量:2

Calling JavaScript functions as function pointers from C

You can use addFunction to return an integer value that represents a function pointer. Passing that integer to C code then lets it call that value as a function pointer, and the JavaScript function you sent to addFunction will be called.

See test_add_function in tests/test_core.py for an example.

When using addFunction, there is a backing array where these functions are stored. This array must be explicitly sized, which can be done via a compile-time setting, RESERVED_FUNCTION_POINTERS. For example, to reserve space for 20 functions to be added:

emcc ... -s RESERVED_FUNCTION_POINTERS=20 ...

Note

When using addFunction on LLVM wasm backend, you need to provide an additional second argument, a Wasm function signature string. Each character within a signature string represents a type. The first character represents the return type of a function, and remaining characters are for parameter types.

  • 'v': void type
  • 'i': 32-bit integer type
  • 'j': 64-bit integer type (currently does not exist in JavaScript)
  • 'f': 32-bit float type
  • 'd': 64-bit float type

For example, if you add a function that takes an integer and does not return anything, you can do addFunction(your_function, 'vi');. See tests/interop/test_add_function_post.js for an example.

https://emscripten.org/docs/porting/connecting_cpp_and_javascript/Interacting-with-code.html#calling-javascript-functions-as-function-pointers-from-c

关注
打赏
1659628745
查看更多评论
立即登录/注册

微信扫码登录

0.0429s