[C++-sig] Re: boost/python: how to: call memberfunctions of an existing c++ object from python?

David Abrahams dave at boost-consulting.com
Thu Mar 10 15:38:33 CET 2005


Stefan Seefeld <seefeld at sympatico.ca> writes:

> Hi Marco,
>
> as I ran into a seemingly similar issue recently, I may be able to provide
> some help here.
>
> Marco Borm wrote:
>
>> Now it is possible to create new instances of the class and call them from
>> python. It is also possible to do the following in my c++ object-code: "ret
>> = boost::python::call<int>(PyFunction.ptr(), this );"
>> But now my problem: boost copies the object and passes only that
>> copy to the
>> function.
>
> You may try to replace the call<> above by
>
> boost::python::call<int>(PyFunction.ptr(), boost::python::ptr(this));
>
> which instructs the bpl machinery to really expose 'this' as a reference,
> and not create a copy from it.

      extract<int>( PyFunction( boost::python:;ptr(this) ) )

should work.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




More information about the Cplusplus-sig mailing list