charto / nbind

:sparkles: Magical headers that make your C++ library accessible from JavaScript :rocket:
MIT License
1.98k stars 120 forks source link

.field support for struct's members without getter /setters #89

Open tarun550 opened 7 years ago

tarun550 commented 7 years ago

Embind has a concept of value_objects which allow us to define "fields" of simple structs.

Is there a similar concept in nbind?

I did see a "filed" macro, but there is no mention of it in the documentation. Basically I wish to avoid adding getter/setter code to my existing code base.

jjrv commented 7 years ago

nbind currently has somewhat different kind of value objects explained under using objects. If your C++ class has a fromJS function taking a callback, JavaScript class has a fromJS function taking a callback and you call binding.bind to unite them, then you can pass the objects by value between languages.

The only getter/setter code needed then is a single function in both languages to pass all class members to a callback. Of course this is practical only if there is a small number of them.

A .field method is planned, but not yet implemented.

tarun550 commented 7 years ago

Thanks for the update. Should I closed this issue or keep it opened until the method is implemented?