develooper Front page | perl.perl5.porters | Postings from December 1999

Returning An Array from an Extension

From:
Aby Paul
Date:
December 8, 1999 02:28
Subject:
Returning An Array from an Extension
Message ID:
s84dd045.080@prv-mail20.provo.novell.com
Hi

I have the following code snippet which should return an array. This doesn't seem to work. 
Could someone tell me what is wrong in this code?

SV *retsv=NULL;
AV *av;
int i = 5;
av = newAV();
retsv = newRV(sv_2mortal((SV*)av));
while(--i >= 0) 
{
  av_store(av, i, newSViv(i));
}

ST(2)=sv_2mortal(retsv);

When called from the script, the length is always returned as 1. But I am unable to see the contents. When @x and $z = $x[0] are
printed, it shows nothing.

If I replace 
ST(2)=sv_2mortal(retsv); with sv_setsv(ST(returnIndex),sv_2mortal(retsv));
then I get ARRAY(0x....) for @x and "01234" for $z = $x[0] from the script.
 
Thanks
Aby




nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About