val::operator() with pointer as argument #7084
Comments
Okay, looks like I found a workaround:
X x;
X* ptr = &x;
action(ptr); This works as expected, interesting... |
Well, that would be a bad practice from the JS side (same as storing a reference to a deleted value in C++). I don't consider it a bug. Being able to do this opens many doors when talking about memory management from the C++ side when exposing objects to js. I wrote a small article about this topic and how you can benefit from such constructions: https://blog.codeisc.com/2018/09/15/xlnt-wasm-bindings.html#avoiding-exposed-ownership |
This issue has been automatically marked as stale because there has been no activity in the past year. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant. |
I'm trying to avoid the need of JS users calling
.delete()
on the API by accepting lambdas as actions that work with the objects:The idea is to use it like this:
I realized that embind is copying the object every time I pass it as a parameter, so I tried passing the ptr to
x
:action(&x);
The compiler complains: "Implicitly binding raw pointers is illegal. Specify allow_raw_pointer<arg<?>>"
I see no way of specifying policy in this case.
Is it possible to pass pointers into
val::operator()
?How can I achieve managing memory from C++ and calling JS actions like this in an easy way?
Am I wrong in my assumption that this design would help defining the proper ownership of those objects?
Thanks a lot
The text was updated successfully, but these errors were encountered: