in reply to Re^2: XS: Passing an external library's function a Perl XS callback
in thread SOLVED: XS: Passing an external library's function a Perl XS callback
This is example I'm looking at https://metacpan.org/pod/perlembed#Fiddling-with-the-Perl-stack-from-your-C-program and I think you could copy this example and turn it into void callback(),
something like
// static void PerlPower(int a, int b) static void callback() { dSP; /* initialize stack pointer */ ENTER; /* everything created after here */ SAVETMPS; /* ...is a temporary variable. */ PUSHMARK(SP); /* remember the stack pointer */ XPUSHs(sv_2mortal(newSViv(a))); /* push the base onto the stack */ XPUSHs(sv_2mortal(newSViv(b))); /* push the exponent onto stack */ PUTBACK; /* make local stack pointer global */ // call_pv("expo", G_SCALAR|G_DISCARD|G_NOARGS); /* call the fu +nction */ call_pv("p_callback", G_DISCARD|G_NOARGS); SPAGAIN; /* refresh stack pointer */ /* pop the return value from stack */ // printf ("%d to the %dth power is %d.\n", a, b, POPi); PUTBACK; FREETMPS; /* free that return value */ LEAVE; /* ...and the XPUSHed "mortal" args.*/ }
Yes , I understand perlcall gives simpler example like you have , but its what I would try, to see if anything sticks :D
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: XS: Passing an external library's function a Perl XS callback
by stevieb (Canon) on Aug 14, 2016 at 21:59 UTC | |
by syphilis (Archbishop) on Aug 14, 2016 at 23:38 UTC | |
by stevieb (Canon) on Aug 15, 2016 at 13:27 UTC |