[C++-sig] Convert C++ Class to exposed class and back

Stefan Seefeld seefeld at sympatico.ca
Tue Feb 12 13:45:23 CET 2008

Marcus Jannes wrote:
> It should read ExpClass not c_class here of course:
> ExpClass pycall(ExpClass c){
>          PyObject *py_obj;
>          ExpClass c_result;
>          py_obj = PyBuildValue("O",c); //does not work! Provide converter function with "O&" argument ?
>          c_result = SomeConverterToC(py_obj); //???
>          return c_result;

What are you trying to do here ? What is 'c' ? There shouldn't be any 
need to use PyObject raw pointers at all. Assuming 'ExpClass' has 
already been exported, the following should Just Work:

ExpClass a = ...;
bp::object o(a); //<--- now holds a copy of 'a'
ExpClass b = bp::extract<ExpClass>(o); //<--- attempts to extract an
                                        //     ExpClass from 'o'

> };

Just declare 'pycall' in your module:

bp::def("pycall", pycall);



       ...ich hab' noch einen Koffer in Berlin...

More information about the Cplusplus-sig mailing list