From: Haoyu B. <div...@gm...> - 2009-04-27 06:49:38
|
On Thu, Apr 23, 2009 at 4:51 PM, <ali...@uk...> wrote: > Hi, > Very much newbie, so apologies if this is all obvious; > > I'd like to use swig to provide information about my deeply nested series > of C-structures > and ultimately turn this into a graph representation. > > I have the following code in example.h > struct Foo > { > int a; > }; > > struct Bar > { > int y; > int * MyPtr; > Foo * MyPtrF; > Foo MyF; > }; > > and the following in example.i > %module example > > %{ > #include "example.h" > %} > > > /* Let's just grab the original header file here */ > %include "example.h" > > And I generate Python code from swig. I would like to be able to get the > type of MyPtr (ie int * - or at least int) and MyPtrF. > However, as the swig docs say, pointers seem to be opaque types, ie you > have no idea what type they are until you try to assignment. > > However, clearly python "knows" what type the pointer is, because it does > strong (/strict) runtime type-checking. I can't assign an int to MyPtrF. > So, is there a way of persuading swig/python to give me this information in > a sensible way? > > Many Thanks > > > Sorry, but what you want? It is unclear for me. If you want the representation of type info of wrapped object, there's some way for it. For example: In [2]: a=operbool.Test() In [4]: a Out[4]: <operbool.Test; proxy of <Swig Object of type 'Test *' at 0x8d380e0> > In [5]: str(a) Out[5]: "<operbool.Test; proxy of <Swig Object of type 'Test *' at 0x8d381c0> >" In [6]: type(a) Out[6]: <class 'operbool.Test'> Where operbool is a swig wrapped module at there, and Test is a SWIG wrapped C++ class. -- Haoyu Bai |