[C++-sig] back-embedding... is this possible?

Roman Yakovenko roman.yakovenko at gmail.com
Mon Jul 10 10:54:37 CEST 2006


On 7/10/06, blairs at free.fr <blairs at free.fr> wrote:
> 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

-- 
Roman Yakovenko
C++ Python language binding
http://www.language-binding.net/



More information about the Cplusplus-sig mailing list