[C++-sig] Re :Re: back-embedding... is this possible?
blairs at free.fr
blairs at free.fr
Mon Jul 10 12:34:47 CEST 2006
> > ok my project looks like this :
> >
> > // my boost-python module
> >
> > struct A
> > {
> > A(){}
> > void toto(){...}
> > };
> >
> > BOOST_PYTHON_MODULE(my_module)
> > {
> > class_<A>("A", init<>())
> > .def("toto", &A::toto);
> > }
> >
> >
> >
> > /// my final C++ program
> >
> > int main()
> > {
> > A a;
> > //do sum c++ stuff
> >
> > //start the python interpreter...
> >
> > PyRun_String("import my_module");
> > reverse_extract<class_<A>>(a, __mainmodule__,"a"); //this is, symbolically,
> what
> > I want to do
> > PyRun_String("a.toto()");
> >
> > ...
> > }
> >
> > is this behaviour possible to create?
>
> This does almost exactly what you want:
>
http://boost.org/libs/python/doc/tutorial/doc/html/python/embedding.html#python.using_the_interpreter
>
I can create the instance in python with
PyRun_String("a =A()");
then handle a in C++ with
A& a = extract<A&>(main_namespace["a"]);
but I don't get it from this tutorial how to create the instance in c++ then
handle it in python
More information about the Cplusplus-sig
mailing list