[C++-sig] Wrapping a function that takes class type, such as type_info
Jim Bosch
talljimbo at gmail.com
Sat Feb 25 04:56:57 CET 2012
On 02/24/2012 02:31 AM, Adam Preble wrote:
> Jim,
>
> I'll top post since I think this might get messy nice and fast
> otherwise. I found I couldn't get to a method wrapped to type a
> PyTypeObject* and only PyObject* would do.
Yeah, that's not surprising. You can also have it take a
boost::python::object; that's essentially a smart pointer for PyObject*.
> if(PyObject_IsInstance((PyObject*) internal_type, noIdea) == 1)
I think this is the only line that needs to change; you just need to use
PyObject_IsSubClass instead of PyObject_IsInstance.
Right now you're asking whether "internal_type" is an instance of
"noIdea", so the answer is only True when "noIdea" is "type".
I think you want to ask whether "internal_type" is a subclass of
"noIdea". And that's just:
if (PyObject_IsInstance((PyObject*)internal_type, noIdea) == 1)
Jim
More information about the Cplusplus-sig
mailing list