
tals
Novice
Sep 17, 2011, 11:14 PM
Post #2 of 2
(1249 views)
|
|
Re: [tals] calling back to perl function from in "inline c" function.
[In reply to]
|
Can't Post
|
|
Update, done. Thanks, TalS. test.pl (callback + passign parameters)
#!/perl use strict; use warnings; use Data::Dumper; use Inline 'C'; printf "myfun pointer from perl %d\n", \&myfun; tstCall(\&myfun, 12, "testing 123!!"); sub myfun { print Dumper \@_; print "doing somethings\n"; } __END__ __C__ #include <stdio.h> void tstCall(unsigned int a, unsigned int b, char* c); void tstCall(unsigned int a, unsigned int b, char* c){ printf("callback function pointer = %d\n", a); void (*callback)(void); // void __stdcall (*callback)(void); // void __cdecl (*callback)(void); // callback=(void *)a; // callback(); dSP; PUSHMARK(SP); XPUSHs(sv_2mortal(newSVuv(b))); XPUSHs(sv_2mortal(newSVpv(c, 0))); PUTBACK; call_sv((SV*)a, G_VOID); FREETMPS; LEAVE; printf("returned from callback function\n"); }
|