Interrogate questions

Hello,

So far I have been using the C++ Python API directly for writing extension modules for Panda3D. Last week I have been dabbling around with Panda3D’s interrogate tool, and some questions popped up:

(1) Can interrogate create Python attributes for published members of C++ classes? For example, if you have a C++ class “Foo” with a member “int i;” and then use “interogate.exe” to create a Python wrapper. Is there a way to have a Python class “Foo”, with an attribute “Foo.i”?

I had a look at the interrogate source code, but I didn’t find anything. But I don’t know if I have been looking at the right places.

(2) Is there a way to pass dictionaries as method arguments for methods wrapped with interrogate? What would be the corresponding C++ datatype? std::map< PyObject*, PyObject* > perhaps.

(3) To create Python classes which support the number or sequence protocol, is it enough to define the proper C++ operators, and interrogate will do the rest? For example:

  INLINE Foo operator + (const Foo &other) const;

enn0x

(1) No. At one point we had intended to add this feature, but we realized we didn’t need it, so we left it out. You have to define accessors for any data members.

(2) Well, there’s no explicit support for dictionaries or any other high-level Python construct, but you can define a function with a PyObject * parameter, which will receive any Python object whatsoever including a dictionary. Then you can use the standard Python/C API calls to verify that you received a dictionary, and to operate on the dictionary.

(3) In general, yes. Interrogate will convert C++ operators to the equivalent Python operators. There are a few cases where there’s not a one-to-one mapping, but in general, it works the way you expect it to.

David

Ok thanks for the explanations.

get/set methods is fine for (1), so I will do it this way.

After thinking about it for some time (2) (passing Python dictionaries) doesn’t make much sense anyway, since it would make it very hard to use this class from the C++ layer. So forget about this question.

And (3) works perfect :slight_smile:

enn0x