|
Boost Users : |
From: Phil Austin (paustin_at_[hidden])
Date: 2001-11-23 19:55:07
(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_at_[hidden]?)
dkottowk_at_[hidden] 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
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net