[C++-sig] Converting C++ Class into Python Binding
clay at idleengineer.net
Wed Feb 16 10:28:59 CET 2005
Lets say I have a library written in C++ called Foo. This library has
been exposed with boost.python so I can use it in python.
I'm writing a program that embeds python into a C++ program, and both
the C++ program and the embedded python scripts will use the Foo library
and share objects. Here's my problem:
I want to take an object of type Bar (from the Foo library) that has
been created in C++ and return it based on a function call in python (I
need a reference, not a copy of the object). To do this, I need to
convert from the C++ class into a PyObject. I'm up to this point:
static PyObject *
get_foo_object( PyObject *self, PyObject *args )
// parse params
// get the Bar object "bar"
Basically I have the object bar, but I need to return a reference to bar
as a PyObject. Since the Bar class exists in both the C++ code and in
the python bindings I think this should be simple, but I can't seem to
figure out how to convert from the C++ object to the Python object.
Any suggestions on how this is done? (Or just link me to documentation
where this is explained. I'm still new to boost.python, and my searches
didn't give me what I was looking for.)
More information about the Cplusplus-sig