syphilis has asked for the wisdom of the Perl Monks concerning the following question:
As can be seen, the "call_Adder" XSub passes its arguments on to the "Adder" perl sub, and then returns the same value as "Adder" itself has returned.use warnings; use Inline C => Config => BUILD_NOISY => 1; use Inline C => <<'EOC'; SV * call_Adder(SV * a, SV * b) { dSP; I32 ax; int count; PUSHMARK(SP); XPUSHs(a); XPUSHs(b); PUTBACK; count = call_pv("Adder", G_SCALAR); SPAGAIN; SP -= count; ax = (SP - PL_stack_base) + 1; if (count != 1) croak("Big trouble\n"); /* Avoid "Attempt to free unreferenced scalar" warning */ SvREFCNT_inc(ST(0)); return ST(0); } EOC my $val = call_Adder(13,118); print $val, "\n"; my $val2 = call_Adder(14,119); print $val2, "\n"; my $val3 = call_Adder(14,8); print $val3, "\n"; sub Adder { my($a, $b) = @_; $a + $b; } __END__ Outputs (as expected): 131 133 22
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: [XS] Callbacks to perl
by bulk88 (Priest) on Jun 17, 2012 at 18:46 UTC | |
by syphilis (Archbishop) on Jun 18, 2012 at 01:07 UTC | |
by bulk88 (Priest) on Jun 18, 2012 at 05:11 UTC | |
by syphilis (Archbishop) on Jun 18, 2012 at 09:37 UTC | |
|
Re: [XS] Callbacks to perl
by ikegami (Patriarch) on Jun 18, 2012 at 05:24 UTC | |
|
Re: [XS] Callbacks to perl
by BrowserUk (Patriarch) on Jun 17, 2012 at 16:39 UTC |