How to access an Array and a struct within a struct wrapped by Swig ?
anishchapagain at gmail.com
Sat Aug 16 20:05:52 CEST 2008
If you have struct defined in .h file then it's ok or can dea easyily
with struct written with .i file,
in .h file,
can be referenced as
>>strvar=new_def() //now strvar is your
object for struct def
and can access a and name as, get and
set for individual member see,
>>def_a_get(strvar) will return 10.
or you can define struct as,
within .h file and access similarly.
On Aug 16, 11:38 am, emmanuel.rivo... at gmail.com wrote:
> I spent almost a week to be able to embed Python within my C++ game
> I wrote a mini-tutorial of what I was able to do so far here :http://forums.indiegamer.com/showpost.php?p=169352&postcount=9
> At the end of my tutorial, I wrote : "You can do the same with C++
> classes, and with structures within structures. Swig can parse & wrap
> most C/C++ declarations."
> Gloups, I was so wrong..! :-S
> It seems that I can read a struct within my struct, but I cannot write
> values to it.
> Also, I cannot access the array from within my struct.
> Any help to achieve this would be very welcome.
> Here the problem in detail :
> I'm using Python 2.5.2 & Swig 1.3.36.
> The structures :
> struct SIn
> int in1, in2;
> struct SPythoned
> SIn Inner;
> float Skill;
> The python code :
> def TestObject(o):
> o.Inner.in1 = 12
> o.Inner.in2 = 17
> It gives me this output :
> <class 'TE2008.SPythoned'>
> <type 'PySwigObject'>
> <class 'TE2008.SIn'>
> <type 'int'>
> So althought I can read the value, the "o.Inner.inX = Y" are without
> effect..! (and checking the value in the object in the C part confirms
> Moreover, if I add these lines :
> for i in range(16) :
> I get this error :
> Traceback (most recent call last):
> File "d:\TE 2008\PyTest.py", line 32, in TestObject
> TypeError: 'PySwigObject' object is unsubscriptable
> Any idea how to make this work ..?
More information about the Python-list