Re: [boost] how to get a *real* copy of a boost-python object that supports virtual function
(I'm posting to both boost and boost-users, but I'm assuming we're supposed to move this kind of discussion to Boost-Users@yahoogroups.com?) dkottowk@yahoo.com writes: [snip]
my question is, how do i get a copy of PyGenome_Callback, which also is a copy of the python-side of the object ?
I'd also be interested in a pointer to an elegant way to do this, as well as an example of a from_python function that converts PyObject* to PyGenome_Callback. Brute force does work for me -- i.e. if you need the derived class and can't construct the object in Python code, you can call the derived constructor from the C++ side like this: PyObject* theMod=PyImport_ImportModule("mymodule"); PyObject* theDict=PyModule_GetDict(theMod); py::ref theRef(theDict); py::dictionary modDict(theRef); py::ref constructor=bDict.get_item(py::string("theObject").reference()); PyObject* theInstance=PyObject_CallObject(constructor.get(),0); This was ugly enough so that I added a python wrapper around my extension to construct the derived objects I needed in Python and pass them back to C++. Phil
participants (1)
-
Phil Austin