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

Stefan Seefeld seefeld at sympatico.ca
Tue Feb 12 14:27:05 CET 2008


Marcus Jannes wrote:
> 
>> 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(o); //<--- attempts to extract an
>>                                         //     ExpClass from 'o'
>>
>>> };
> 
> Thank you, this seems to go into the right direction, but i need the PyObject pointer for a function like:
> PyEval_CallObject();

Why ? Have you studied the boost.python documentation at all ? It offers 
everything you need to call a python object from within C++ code, 
without having to touch the Python C API.

(But to answer your question: python::object has a 'ptr()' member 
function that returns a raw pointer, if you *really* need it.)

HTH,
		Stefan

-- 

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



More information about the Cplusplus-sig mailing list