CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
calling back to perl function from in "inline c" function.

 



tals
Novice

Sep 16, 2011, 1:55 AM

Post #1 of 2 (1735 views)
calling back to perl function from in "inline c" function. Can't Post

Dear All,

I need help to call back to a Perl function from in an "inline c" function.

For some reason the script stalled when I call back to the Perl function.

any ideas ??

Thanks,
TalS.

test.pl

Code
#!/perl 

use strict;
use warnings;
use Data::Dumper;

use Inline 'C';


printf "myfun pointer from perl %d\n", \&myfun;
tstCall(\&myfun);

sub myfun {
print "doing somethings\n";
}


__END__
__C__
#include <stdio.h>

void tstCall(unsigned int a);

void tstCall(unsigned int a){
printf("callback function pointer = %d\n", a);

void (*callback)(void);
// void __stdcall (*callback)(void);
// void __cdecl (*callback)(void);
callback=(void *)a;
callback();

printf("returned from callback function\n");
}



tals
Novice

Sep 17, 2011, 11:14 PM

Post #2 of 2 (1647 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)

Code
#!/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");
}


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives