Boost logo

Boost :

From: Marco Borm ([hidden])
Date: 2005-03-10 06:16:14

David Abrahams wrote:
> Marco Borm <[hidden]> writes:
>>It is also possible to do the following in my c++
>>object-code: "ret = boost::python::call<int>(PyFunction.ptr(), this );"
> But not so elegant or safe as:
> ret = boost::python::extract<int>( PyFunction( *this ) );
thats true :-)

>>But now my problem: boost copies the object and passes only that
>>copy to the function. Is it and how is it possible to make the
>>object accessible to the function within the python-script?
> ret = boost::python::extract<int>( PyFunction( boost::ref(*this) ) );
To clarify: "this" isn't an instance of an boost/python object.
The Instance is created somewhere else without boost/python.
Because this, the code you gave me crashs in wrapper_base.hpp on an
"dynamic_cast<wrapper_base const volatile*>(x)"

An example for what I want:
class CppClass {
  void foo();
  void bar();

     boost::python::class_<CppClass>("CppClass", boost::python::no_init)
         .def("bar", &CppClass::bar)

void CppClass::foo()
   // call "foohelper" in python-script
   ret = boost::python::extract<int>( PyFunction( boost::ref(*this) ) );

// python script
def foohelper(cppobj):
        return 1234;

   CppClass* object = new CppClass;

Thanks for help!
Marco Borm

Boost list run by bdawes at, gregod at, cpdaniel at, john at