I am looking for a simple way to expose a C++ class instance to a python embedded interpreter.
- I have a C++ library. This library is wrapped (using swig for the moment) and I am able to use it from the python interpreter
- I have a C++ main program which instanciates a Foo class from my library and embeds a python interpreter
I would like to expose my C++ world instance of Foo to the python world (and seen as a Foo class).
Is this possible, if so, how?
I think it's almost like in the first answer of : boost::python::ptr or PyInstance_New usage
I guess this means I should use boost.Python
to wrap my library?
My only goal is to manipulate my C++ instance of Foo in the embedded python interpreter (not sure that it can be done with the previous method).
In fact, I already have exposed my Foo class to python (with swig).
What I have:
my Foo class:
class Foo{...};
my wrapped library (including the Foo class) exposed to python: so I can start the python interpreter and do something like this :
import my_module
foo=my_modulde.Foo()
What I want:
Having a C++ main program which embeds a python interpreter and manipulates C++ world variables.
int main(int argc, char **argv)
{
Foo foo; // instanciates foo
Py_Initialize();
Py_Main(argc, argv); // starts the python interpreter
// and manipulates THE foo instance in it
Py_Finalize();
return 0;
}