jrs has asked for the wisdom of the Perl Monks concerning the following question:
Will anyone please let me know what I'm doing wrong?
thanks
-- Jonathan
jrs@madrona emperl$ ls -la
total 24 drwxrwxr-x 2 jrs jrs 4096 Jun 13 08:14 . drwx------ 80 jrs jrs 12288 Jun 12 19:54 .. -rw-rw-r-- 1 jrs jrs 756 Jun 13 08:07 main.c -rw-rw-r-- 1 jrs jrs 127 Jun 13 08:14 test.pl
#!/usr/bin/perl -w use strict; sub reverse_string { my ($string) = @_; my $rev = reverse $string; return $rev; }
#include <stdio.h> #include <EXTERN.h> #include <perl.h> static PerlInterpreter *my_perl; int main(int argc, char **argv, char **env) { char in_string[] = "abcdefg"; char *out_string; char *embedding[] = { "", "test.pl" }; PERL_SYS_INIT3(&argc,&argv,&env); my_perl = perl_alloc(); perl_construct(my_perl); perl_parse(my_perl, NULL, 2, embedding, NULL); dSP; ENTER; SAVETMPS; PUSHMARK(sp); XPUSHs(sv_2mortal(newSVpv(in_string, 0))); PUTBACK; perl_call_pv("reverse_string", G_SCALAR); SPAGAIN; out_string = POPp; PUTBACK; FREETMPS; LEAVE; printf ("reverse %s -> %s\n", in_string, out_string); perl_destruct(my_perl); perl_free(my_perl); PERL_SYS_TERM(); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: embedding perl in c?
by almut (Canon) on Jun 13, 2008 at 16:38 UTC | |
by jrs (Initiate) on Jun 13, 2008 at 17:22 UTC |