[C++-sig] RE: [boost] mirroring class instances between c++ and python

David Abrahams david.abrahams at rcn.com
Sun Jun 2 07:09:55 CEST 2002


From: "David GD Wilson" <firestar at thenorth.org>


> Dave,
>
> Thanks for the response. I have looked into the method you have
> suggested below. However unsure how I can create a CTest instance within
> my c++ code? I can see how it will work if I create the CTest/PTest from
> inside python, but I need to create the CTest/PTest from c++.
>
> Is this going to be possible with the method you have suggested?

Sure. Just use

    class_builder<CTest,CTest> c_test;
    c_test.def_init(constructor<Arg1,Arg2...>());
    ...
    // Get the class object
    PyTypeObject* PTest = c_test.get_extension_class();
    ...

    // call the Python class to make a new instance.
    python::ref x = python::callback<python::ref>::call((PyObject*)PTest,
a1, a2...)

where a1, a2... are the constructor arguments.

Now x manages a Python PTest object which holds a CTest instance.

-Dave







More information about the Cplusplus-sig mailing list