Multiple +add_on_binder directives for a class/struct
Simon-L opened this issue · 3 comments
I noted that multiple add_on directives on the same class/struct are ignored except the last one in the config file. Is there a reason for that?
To circumvent this I just add the needed code as a single line in config:
+add_on_binder target::class cl.def_readwrite("target1", &target::class::target1); cl.def_readwrite("target2", target::class::target2);
I have also noticed that binder adds (cl);
at the end of the add_on line, why is that so?
I have used binder to generated bindings for the codebase of VCV Rack, an open source virtual modular music software.
For ease of use I have directly included the files from Rack's include
directory.
A lot of fields in the structs are either extern
or initialized as NULL
and they were skipped by binder and do not appear in the generated bindings, hence why I manually re-add the missing fields using add_on. Examples here and here
Adding another similar comment/question to this:
def_readwrite
works fine for classes but for replicating C++ namespaces' member variables inside modules, I have no idea how else to bind such a variable other than by manually adding a getter and a setter function.
M("rack::settings").attr("foo") = &rack::settings::foo
doesn't seem to "work".
Example of a variable that I need the module to bind to: https://github.com/VCVRack/Rack/blob/v2/include/asset.hpp#L40
This is expected behavior: Binder add_on_binder
directive intended usage is to provide name of the binding-function (and not lines of code which will be problematic due to need to fix names of local variables and context). Please see https://cppbinder.readthedocs.io/en/latest/config.html#config-file-options for details.
A lot of fields in the structs are either extern or initialized as NULL and they were skipped by binder and do not appear in the generated bindings, hence why I manually re-add the missing fields using add_on.
-- reason for skipping these fields is that they are pointers, - bindings data member with types of raw pointers (as well as reference and arrays) are not supported.
re global data member for modules: Binder currently not supporting this. Not sure if it possible to do this manually, probably best to contact Pybind11 team on this.
I am closing this for now but please feel free to re-open if you need more help on this.
Forgot to mention: workaround for lack of bindings of module-global data members would be to provide static function get_my_data_struct
which will return reference to global data struct. Hope this helps,