ccad has asked for the wisdom of the Perl Monks concerning the following question:
Has anyone an idea? Many thanks in advance! Frank/********************************************** * 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 <EXTERN.h> #include <perl.h> #include <stdio.h> /*--------------------------------------------- * 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; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: embedding Perl into C for Windows
by syphilis (Archbishop) on Feb 11, 2014 at 23:55 UTC | |
by ccad (Novice) on Feb 12, 2014 at 07:24 UTC | |
|
Re: embedding Perl into C for Windows
by Anonymous Monk on Feb 11, 2014 at 21:23 UTC | |
by bulk88 (Priest) on Feb 12, 2014 at 01:38 UTC | |
by ccad (Novice) on Feb 12, 2014 at 07:25 UTC | |
by ccad (Novice) on Feb 12, 2014 at 07:28 UTC |