| 1 | #include <EXTERN.h> /* from the Perl distribution */ |
| 2 | #include <perl.h> /* from the Perl distribution */ |
| 3 | static PerlInterpreter *my_perl = NULL; /*** The Perl interpreter ***/ |
| 4 | |
| 5 | //dynaloader |
| 6 | static void xs_init (pTHX); |
| 7 | EXTERN_C void boot_DynaLoader (pTHX_ CV* cv); |
| 8 | EXTERN_C void boot_Socket (pTHX_ CV* cv); |
| 9 | EXTERN_C void |
| 10 | xs_init(pTHX) { |
| 11 | char *file = __FILE__; |
| 12 | newXS("DynaLoader::boot_DynaLoader", boot_DynaLoader, file); //DynaLoader is a special case |
| 13 | } |
| 14 | //dynaloader - end |
| 15 | |
| 16 | |
| 17 | int main(int argc, char **argv, char **env) { |
| 18 | my_perl = perl_alloc(); |
| 19 | perl_construct(my_perl); |
| 20 | |
| 21 | if(0) { //interactive? |
| 22 | perl_parse(my_perl, xs_init, argc, argv, (char **)NULL); |
| 23 | } else { |
| 24 | char *embedding[] = { "", "-e", "0" }; |
| 25 | //perl_parse(my_perl, NULL, 3, embedding, NULL); //no dynamic loader |
| 26 | perl_parse(my_perl, xs_init, 3, embedding, NULL); |
| 27 | } |
| 28 | |
| 29 | eval_pv( |
| 30 | "use LWP::Simple; getprint('http://harvie.cz/');" |
| 31 | "print('lol\n');" |
| 32 | , TRUE); |
| 33 | //eval_pv("$a = 3; $a **= 2", TRUE); printf("a = %d\n", SvIV(get_sv("a", FALSE))); |
| 34 | //eval_pv("$a = 3.14; $a **= 2", TRUE); printf("a = %f\n", SvNV(get_sv("a", FALSE))); |
| 35 | //eval_pv("$a = 'rekcaH lreP rehtonA tsuJ'; $a = reverse($a);", TRUE); printf("a = %s\n", SvPV(get_sv("a", FALSE), n_a)); |
| 36 | |
| 37 | perl_run(my_perl); |
| 38 | perl_destruct(my_perl); |
| 39 | perl_free(my_perl); |
| 40 | } |