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

Marcus Jannes jannes80 at hotmail.de
Tue Feb 12 14:50:08 CET 2008

Thank you, i think this is exactly what i need. Regarding your question why i want to use it in this way:
It is because i want to convert Python function objects to C++ function pointers which get passed to a another function and this seems to be the way to do it. The boost.python FAQ (see: http://www.boost.org/libs/python/doc/v2/faq.html ) states that it isnt possible, unless i misunderstood it. So i am trying it in C API. Now i should be able to :-). If there is any better way to do it, i would be happy to know.

> Date: Tue, 12 Feb 2008 08:27:05 -0500
> From: seefeld at sympatico.ca
> To: c++-sig at python.org
> Subject: Re: [C++-sig] Convert C++ Class to exposed class and back
> 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...
> _______________________________________________
> C++-sig mailing list
> C++-sig at python.org
> http://mail.python.org/mailman/listinfo/c++-sig

Kostenlose Messenger Emoticons! Hier downloaden!

More information about the Cplusplus-sig mailing list