airween has asked for the wisdom of the Perl Monks concerning the following question:
#ifdef SWIGPERL
%typemap(out) int [ANY] {
AV * av = newAV();
int i = 0,len = 0;
printf("len: %d\n", $1_dim0);
len = $1_dim0;
for (i = 0; i < len ; i++) {
SV* perlval = newSV(0);
sv_setiv(perlval, (IV)$1i);
av_store(av, i, perlval);
}
$result = newRV_noinc((SV *)av);
}
#endif
The name of the variable is "m" in C source, and that a structure. It has a member, called "ilist" (integer list). In Python, I can access to this list like this:print m.ilist // produces [0, 3, 6, ....]In Perl, I just get this:
#!/usr/bin/perl
use example1;
my @m = $example1::m->{ilist};
foreach(@m) {
print $i, "'", $_, "'\n";
$i=$i+1;
}
this produces:0''and nothing more.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl array with SWIG
by choroba (Cardinal) on Jun 05, 2016 at 12:41 UTC | |
|
Re: Perl array with SWIG
by airween (Initiate) on Jun 07, 2016 at 14:03 UTC |