
Marco Borm <mb.ml.boost@adisoft-systems.de> 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 ) );
David Abrahams wrote: 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 { public: void foo(); void bar(); .... }; BOOST_PYTHON_MODULE(test) { 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): cppobj.bar() return 1234; main() { CppClass* object = new CppClass; object->foo(); } Thanks for help! Marco Borm