/********************************************** * C calls a Perl subroutine and pushes two * double scalars.These two scalars are modified * in the sub and popped. * 7.2.2014 Frank **********************************************/ #include #include #include /*--------------------------------------------- * global variables *--------------------------------------------*/ double x, y; int icoun; static PerlInterpreter *my_perl; /*--------------------------------------------- * the C-"Assembly"routine *--------------------------------------------*/ static void harry(double x, double y) { printf("in Harry vor call, x= %lf, y= %lf\n",x,y); dSP; ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs(sv_2mortal(newSVnv(x))); // PUSH one double "n" XPUSHs(sv_2mortal(newSVnv(y))); // PUSH one double "n" PUTBACK; icoun= call_pv("points",G_ARRAY); SPAGAIN; y= POPn; // POP one double "n" x= POPn; // POP one double "n" printf("in Harry after call, icoun= %d, x= %lf, y= %lf\n",icoun,x,y); PUTBACK; FREETMPS; LEAVE; } /*--------------------------------------------- * main *--------------------------------------------*/ int main(int argc, char **argv, char **env) { char *my_argv[]= {"", "punkte2.pl"}; x= 3.1416; y= 47.11; printf("Controll of the entry values\n"); printf("X= %lf, Y= %lf\n",x,y); /*============================================= * start Perl Interpreter *============================================*/ my_perl= perl_alloc(); perl_construct(my_perl); perl_parse(my_perl,NULL, 2, my_argv, (char **)NULL); perl_run(my_perl); /*============================================= * launch the C-"Assembly" routine *============================================*/ harry(x,y); /*============================================= * ...and clean up *============================================*/ perl_destruct(my_perl); perl_free(my_perl); } #********************************************* # the Subroutine points # 7.2.2014 Frank #********************************************* sub points { my ($xup,$yup)= @_; # value,value print "in der Subroutine\n"; # kleiner Test print "XUP= $xup, YUP= $yup\n"; $xup *= 3; $yup *= 4; return $xup, $yup; }