Some problems about embind

484 views
Skip to first unread message

Qiang Li

unread,
Jun 21, 2021, 4:23:49 AM6/21/21
to emscripte...@googlegroups.com
Hi
    I encountered some problems in using embind. I have a function in class which parameter is an original pointer of char type. When I registered the function with embind, I got the following error, hoping to get an answer.
image.png
image.png
image.png

Qiang Li

unread,
Jun 21, 2021, 4:38:30 AM6/21/21
to emscripte...@googlegroups.com
Hi
    I encountered some problems in using embind. I have a function in class which parameter is an original pointer of char type. When I registered the function with embind, I got the following error, hoping to get an answer.
error log:
    emsdk-1.39.20/upstream/emscripten/system/include/emscripten/wire.h:120:13: error: static_assert failed due to requirement '!std::is_pointer<unsigned char *>::value' "Implicitly binding raw pointers is illegal.  Specify allow_raw_pointer<arg<?>>"
            static_assert(!std::is_pointer<T*>::value, "Implicitly binding raw pointers is illegal.  Specify allow_raw_pointer<arg<?>>");

code:
   std::vector<re> Wasm_bind_test::decete_wasm(unsigned char *rgba_) {}

    EMSCRIPTEN_BINDINGS(my_class) {
emscripten::class_<Wasm_bind_test>("Wasm_bind_test")
.constructor<>()
.function("decete_init",&Wasm_bind_test::decete_init)
.function("decete_wasm",&Wasm_bind_test::decete_wasm)
;
emscripten::register_vector<re>("Vectorresult");
emscripten::value_object<re>("re")
.field("left",&re::left)
.field("top",&re::top)
.field("right",&re::right)
.field("bottom",&re::bottom)
;

};

Shachar Langbeheim

unread,
Jun 21, 2021, 4:50:33 AM6/21/21
to emscripten-discuss
https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html#embind-raw-pointers
Using raw pointers isn't allowed by default. In order to do it requires explicitly stating that you do it.

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAAw1VV%2BWdyM1Xu3xfzvs5qbMz8Z2c8U5%2BhFsB6XXj0%2B6P%2BjjOQ%40mail.gmail.com.

Qiang Li

unread,
Jun 21, 2021, 5:26:01 AM6/21/21
to emscripte...@googlegroups.com
Thank you for response!
    But I added allow_raw_pointers() When running, JS will report the error "Cannot call Wasm_bind_test.decete_wasm due to unbound types: Ph", what is the reason for this error?

Shachar Langbeheim <nih...@gmail.com> 于2021年6月21日周一 下午4:50写道:

Qiang Li

unread,
Jun 23, 2021, 3:37:25 AM6/23/21
to emscripten-discuss
Thank you for response!
    But I added allow_raw_pointers() When running, JS will report the error "Cannot call Wasm_bind_test.decete_wasm due to unbound types: Ph", what is the reason for this error?

Shachar Langbeheim

unread,
Jun 23, 2021, 4:12:55 AM6/23/21
to emscripten-discuss

Qiang Li

unread,
Jun 23, 2021, 4:58:54 AM6/23/21
to emscripten-discuss
EMSCRIPTEN_BINDINGS(my_class) {
emscripten::class_<Wasm_bind_test>("Wasm_bind_test")
.constructor<>()
.function("decete_init",&Wasm_bind_test::decete_init)
.function("decete_wasm",&Wasm_bind_test::decete_wasm, allow_raw_pointers())
;
Is it bound as in the above code?add allow_raw_pointers()

Qiang Li

unread,
Jun 23, 2021, 6:07:29 AM6/23/21
to emscripten-discuss
The argument in my function is a "unsigned char *ptr" ,What should I do in .function()?

在2021年6月23日星期三 UTC+8 下午4:12:55<nih...@gmail.com> 写道:
Reply all
Reply to author
Forward
0 new messages