I'm not exactly sure of your requirements - you would be better off to provide some simple/minimalist test program that demonstrates what you're attempting to achieve. (Since you have not yet worked out how to achieve what you're after, that test script would presumably not work - but if it gave us some hints regarding the essence of your aims, that might help.)
Here's a basic, contrived example of how the return values of C functions (namely, the foo() and bar() functions) could be fed into the embedded perl process. It's just a slight modification of the 'power.c' example from perlembed:
#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();
}
For that program to work, 'power.pl' needs to be also in the cwd - and needs to contain the following:
sub expo {
my ($a, $b) = @_;
return $a ** $b;
}
Cheers, Rob
|