-
Notifications
You must be signed in to change notification settings - Fork 777
Embind port #7239
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Embind port #7239
Conversation
When using
const ArenaVector<X>* getField() const {
return &field;
}
...
property("field", &Foo::getField, return_value_policy::reference()); |
I played a bit more with your example and I am now running into some other issues using a getter. Since class_<ArenaVectorBase<ArenaVector<int>, int>>("Base")
.function("insertAt", &ArenaVectorBase<ArenaVector<int>, int>::insertAt)
.function("getAt", &ArenaVectorBase<ArenaVector<int>, int>::operator[])
;
class_<ArenaVector<int>, base<ArenaVectorBase<ArenaVector<int>, int>>>("Derived");
However, if I then try to do something like I'm still thinking about how we could better handle this, but a current alternative is to not use a class_<Foo>("Foo").function("getField", +[](Foo& foo) { return &foo.field; }, return_value_policy::reference()); |
I thought about this a little more and the |
Thanks! I'll try a function here. I don't think we need to write to the vector, which is good. |
That gets me a little further. Now I see that some of the automation I was hoping to get will not "just work" as I'd hoped. We can automate creation of |
What is the current state of this PR? |
I haven't had any good ideas on moving forward here, unfortunately. Ideally someone with more expertise in embind might take a look at it. There could be some C++ template magic or embind magic that could help here, that I am not aware of. |
What are the main difficulties? Also, it looks like the changes in this PR would be breaking, as they are not compatible with the current JS API. |
The main issue is that I was hoping this would save a lot of work, but it turns out exposing the C++ API using embind is not that simple due to overloads, as mentioned in #7239 (comment) Given that, I'm not sure if this is worth it or not. But maybe there is a nice way that I am missing. I think a breaking change might make sense here if it had large benefits - it would be a better path forward for the long term. But I don't quite see how to get such benefits here yet. |
Do you want to expose all of the We could add overload support to embind based on type, but it would still require the user to add a binding for each one they want to expose. I'm not aware of any magic c++ templating to match all the overloads (besides using the preprocessor to generate them). I've been hesitant to do type overloading since it would be slow and doesn't really mesh with JS, but we could probably make it so it doesn't affect non-overloaded functions. |
Sort of, yes - my native hope was that we'd expose the C++ API to JS in a simple way, as close as possible. I guess overloading does make it difficult... If there is a better way to do these bindings, I'm open to that. In general I feel like it would be cool if Binaryen had a great bindings story to JS - it could be a showcase for all the work we've done on embind, TypeScript, etc., on the Emscripten side. |
For #6225
Basic stuff works, but I am having trouble with the return policy @brendandahl
I am doing
Reference is what I want for fields which are vectors of names - we don't want to copy them, and they'll be around while the object is. But I get
That requirement for a move constructor or copy assignment operator confuse me, as the docs for a return value policy of reference say "Constructor: none". What am I doing wrong?