On Wed, Dec 03, 2003 at 11:33:53AM -0600 Dan Muey wrote: > Ok, I can compile this example with: > cc -o perlemb perlemb.c `perl -MExtUtils::Embed -e ccopts -e ldopts` > > I can run it like this: > ./perlemb -e 'print "Howdy";' > Howdy > Or > ./perlemb > print "Howdy"; > <cntrl D> > Howdy > > Here's what I have on the inetrnal version (IE the perl to execute is provided > inside and not via cmd line) > > #include <EXTERN.h> /* from the Perl distribution */ > #include <perl.h> /* from the Perl distribution */ > > static PerlInterpreter *my_perl; /*** The Perl interpreter ***/ > > int main(int argc, char **argv, char **env) > { > my_perl = perl_alloc(); > perl_construct(my_perl); > perl_parse(my_perl, NULL, argc, argv, (char **)NULL); > perl_run(my_perl); > perl_destruct(my_perl); > perl_free(my_perl); > } > > What I'd like to do with this is: > > ./perlemb2 > Howdy > And eventually through using CGI's param() perhas: > ./perlemb2 name=JoeMama > Howdy JoeMama
I would assume that this works with the C program in the very same way as it works with Perl. > What I have so far for testing is: > > #include <EXTERN.h> > #include <perl.h> > > static PerlInterpreter *my_perl; > > main (int argc, char **argv, char **env) > { > STRLEN n_a; > const char *perlcode = "use CGI 'header';print header();print 'hello World';"; > > my_perl = perl_alloc(); > perl_construct( my_perl ); > > perl_parse(my_perl, NULL, argc, argv, (char **)NULL); > > perl_run(my_perl); > > printf("%s", SvPV(eval_pv(perlcode))); > > perl_destruct(my_perl); > perl_free(my_perl); > } > > But when I compile it the same way as the first I get: > > perlemb.c:18: macro `SvPV' used with just one arg Yep, indeed, I forgot the second argument. > So I tried it as > printf("%s", SvPV(eval_pv(perlcode),n_a)); > Which is how it was in another example and got: > > perlemb.c: In function `main': > perlemb.c:18: invalid type argument of `->' > perlemb.c:18: invalid type argument of `->' > perlemb.c:18: invalid type argument of `->' > perlemb.c:18: warning: passing arg 1 of `Perl_sv_2pv' makes pointer from integer > without a cast Ah, right. One has to take care with the perlapi since many things are in fact macros and not functions. SvPV() is one and it wont accept an expression. You need to use a proper variable: STRLEN n_a; SV *res = eval_pv(perlcode); printf("%s", SvPV(res, n_a)); Maybe I can also point you to [EMAIL PROTECTED] If you want to do the occasional XS or embedding, this mailing-list is the right place to consult. Tassilo -- $_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({ pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#; $_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]