From: derek_yl <der...@pc...> - 2008-10-26 00:49:24
|
This is what I want to have in Perl script my $foo = new FOO; $foo->{count} = 3; $foo->{array} = [1,2,3]; my @arr = @{$foo->{array}} print $arr[2]; __END__ So in my interface file, I should have typedef struct _FOO { int count; int *array; //number of elements is dynamic } FOO; Then I defined my own getter and setter %extend FOO { void swig_FOO_array_set(???) { //get the array reference, something like SV *sv = ST(1); //save the address to sv in the int pointer, like self->array = sv; } void swig_FOO_array_get() { //get the FOO object, say self //access the address to array reference saved in setter function SV *sv = self->array; //start handling the array reference AV *av = SvRV(sv); // this will not work } } I have 3 questions 1. What should I define for the parameter of swig_FOO_array_set 2. Even I make the setter work in any way, I found the sv retrieved in getter is no longer an valid reference (I use SvROK to check). It seems the memory address is being modified between when I jumped out of setter and called into the getter. What have I done wrong? 3. Is there an better method to achieve the same goal? Thanks. -- View this message in context: http://www.nabble.com/Saving-an-array-reference--tp20160156p20160156.html Sent from the swig-user mailing list archive at Nabble.com. |