[C++-sig] boost/python: how to: call memberfunctions of an existing c++ object from python?
Marco Borm
mb.ml.boost at adisoft-systems.de
Wed Mar 9 17:44:32 CET 2005
(I also posted this message to gmane.comp.lib.boost.devel)
Hi Boost/Python developers,
at first I have to say that I am no boost nor a python expert.
I've searched for hours now on the web for my problem but was unable to find
some solution for my problem:
Currently I am working on the possibility that an python-script is called by
an existing c++ object. This was "easy" to do with and without the boost
python-classes.
To make this more complicate, the script must be able to call some member
functions of this object.
So to make this possible I created an BOOST_PYTHON_MODULE() containing the
class and the to be called member function-definitions.
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.
Is it and how is it possible to make the object accessible to the function
within the python-script?
I have found some hints in the boost-source for using smartptr but I was
unable to use them as an parameter for call(): "TypeError: No to_python
(by-value) converter found for C++ type: class boost::shared_ptr<TYPE>".
I am also don't known if this is the right way to do.
Thanks for help!
Marco Borm
More information about the Cplusplus-sig
mailing list