in reply to Re^2: perl c++ perlembed question
in thread perl c++ perlembed question
For that program to work, 'power.pl' needs to be also in the cwd - and needs to contain the following:#include <EXTERN.h> #include <perl.h> static PerlInterpreter *my_perl; static void PerlPower(int a, int b) { dSP; ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs(sv_2mortal(newSViv(a))); XPUSHs(sv_2mortal(newSViv(b))); PUTBACK; call_pv("expo", G_SCALAR); SPAGAIN; printf ("%d to the %dth power is %d.\n", a, b, POPi); PUTBACK; FREETMPS; LEAVE; } int foo(void) { unsigned long t = (unsigned)time( NULL ); return (t % 5) + 3; } int bar(void) { unsigned long t = (unsigned)time( NULL ); return (t % 4) + 2; } int main (int argc, char **argv, char **env) { char *my_argv[] = { "", "power.pl" }; PERL_SYS_INIT3(&argc,&argv,&env); my_perl = perl_alloc(); perl_construct( my_perl ); perl_parse(my_perl, NULL, 2, my_argv, (char **)NULL); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; perl_run(my_perl); PerlPower(foo(), bar()); /* foo() ** bar() */ perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); }
Cheers,sub expo { my ($a, $b) = @_; return $a ** $b; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: perl c++ perlembed question
by eth0nic (Initiate) on Jun 27, 2009 at 16:28 UTC | |
|
Re^4: perl c++ perlembed question
by Anonymous Monk on Jun 27, 2009 at 16:08 UTC | |
|
Re^4: perl c++ perlembed question
by eth0nic (Initiate) on Jun 27, 2009 at 16:11 UTC | |
by syphilis (Archbishop) on Jun 27, 2009 at 23:53 UTC |