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

In reply to Re^3: perl c++ perlembed question by syphilis
in thread perl c++ perlembed question by eth0nic

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.