in reply to perl XS - passing array to C and getting it back
Because that script specifies CLEAN_AFTER_BUILD=>0 you can then cd into the ./_Inline/build directory and view the XS file that was autogenerated and used.use strict; use warnings; use Math::BigInt; use Inline C => Config => BUILD_NOISY => 1, USING => 'ParseRegExp', CLEAN_AFTER_BUILD => 0, ; use Inline C => <<'EOC'; double do_nothing(SV * x, ...) { dXSARGS; /* enable stack manipulation */ int index; for(index=0; index<items; index++) { printf("%f ", SvNV(ST(index))); ST(index)=newSVnv(1.34); } printf("\n"); return SvNV(ST(0)); } EOC my @in = (2.3, 3.4, 4.5, 6.8); my $d = do_nothing(@in); print $d, "\n"; my @next = (-1.7, -1.3, @in); my $d2 = do_nothing(@next); print $d2, "\n"; __END__ Outputs: 2.300000 3.400000 4.500000 6.800000 1.34 -1.700000 -1.300000 2.300000 3.400000 4.500000 6.800000 1.34
In that case you'd be calling do_nothing() from perl as something like:double do_nothing(SV * x) { ... do stuff }
I can give you a demo of that, too, if you like.my $double = do_nothing(\@in);
|
|---|