Automatically convert Python objects to constant pointer / const struct s *s?
I'm wrapping some functions that look like this: struct data_only { int foo; int bar; int baz[40]; } int use_data(int a, const struct data_only *b) { // ... } I have no trouble converting the struct into Python but I'm unclear how to convert it back. I would like to be able to substitute a dictionary or class with the same properties also, rather than require an instance of that struct. How should I register from-python convertors for this purpose? Thanks, Daniel Holth
Hi Daniel, Daniel Holth wrote:
I have no trouble converting the struct into Python but I'm unclear how to convert it back. I would like to be able to substitute a dictionary or class with the same properties also, rather than require an instance of that struct.
How should I register from-python convertors for this purpose?
I think you don't need a from-python convertor to do this. Just use a wrapper function that accepts a boost::python::object as a parameter: int use_data_wrapper(int a, object data_only) { if ( data_only.attr("foo") == 3 ) { data_only.attr("bar") = 4; } // and etc } Hope that helps, Nicodemus.
participants (2)
-
Daniel Holth -
Nicodemus