L
Lee
Please help: I'm trying to do the my first real thing in Inline::C and
have got stuck trying to get expected values from an array reference.
I pass in an anonymous array of one value, the number 1, and I get back
135435488.
here...
Any help would be appreciated.
Thanks in anticipation
lee
Output from the code below:
$VAR1 = [ 99 ];
$VAR1 = [ 135435488 ];
Code:
#! perl
package Testing;
use strict;
use warnings;
use Data:umper;
use Inline "C";
Inline->init;
my @amps = test( 1, [1] );
warn Dumper @amps;
my @amps = test( 2, [2] );
warn Dumper @amps;
exit;
1;
__DATA__
__C__
AV* test (
int mode,
SV* rpcm
){
AV* av_ret = newAV(); // Return values
AV* av_pcm = newAV(); // Dereferenced PCM input array
if (SvROK(rpcm) && (SvTYPE(SvRV(rpcm)) == SVt_PVAV))
av_pcm = (AV*)SvREFCNT_inc(SvRV(rpcm));
if (mode==1){
int x = 99;
av_push( av_ret, newSViv(x) );
} else {
int x = av_fetch(av_pcm, 0, 0);
av_push( av_ret, newSViv(x) );
}
return av_ret;
}
have got stuck trying to get expected values from an array reference.
I pass in an anonymous array of one value, the number 1, and I get back
135435488.
values in the input array, but I can't figure out where to go fromFrom the code you can see that I realise it is the way I getting at the
here...
Any help would be appreciated.
Thanks in anticipation
lee
Output from the code below:
$VAR1 = [ 99 ];
$VAR1 = [ 135435488 ];
Code:
#! perl
package Testing;
use strict;
use warnings;
use Data:umper;
use Inline "C";
Inline->init;
my @amps = test( 1, [1] );
warn Dumper @amps;
my @amps = test( 2, [2] );
warn Dumper @amps;
exit;
1;
__DATA__
__C__
AV* test (
int mode,
SV* rpcm
){
AV* av_ret = newAV(); // Return values
AV* av_pcm = newAV(); // Dereferenced PCM input array
if (SvROK(rpcm) && (SvTYPE(SvRV(rpcm)) == SVt_PVAV))
av_pcm = (AV*)SvREFCNT_inc(SvRV(rpcm));
if (mode==1){
int x = 99;
av_push( av_ret, newSViv(x) );
} else {
int x = av_fetch(av_pcm, 0, 0);
av_push( av_ret, newSViv(x) );
}
return av_ret;
}