/* moduletext = text of module + "package main; DynTrans->import;" */
eval_pv(moduletext, TRUE); /* ~ use DynTrans; */
eval_pv("$a = fortytwo();", TRUE); /* its function is available */
####
#include
#include
static PerlInterpreter *pi;
/* Note the last two lines "package main; DynTrans->import" */
static char *moduletext =
"package DynTrans;\n\
use base qw/Exporter/;\n\
our @EXPORT;\n\
BEGIN { @EXPORT = qw/&fortytwo/; }\n\
sub fortytwo { 42; }\n\
1;\n\
package main;\n\
DynTrans->import;";
int main(int argc, char **argv, char **env) {
STRLEN n_a;
char *embedding[] = { "", "-e", "0" };
pi = perl_alloc();
perl_construct(pi);
perl_parse(pi, NULL, 3, embedding, NULL);
PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
perl_run(pi);
eval_pv(moduletext, TRUE); /* ~ use DynTrans; */
eval_pv("$a = fortytwo();", TRUE); /* its function is available */
printf("EXPECT: a = 42\nGOT: a = %d\n", SvIV(get_sv("a", FALSE)));
perl_destruct(pi);
perl_free(pi);
return 0;
}
####
OUTPUT:
EXPECT: a = 42
GOT: a = 42