TheGeniuS has asked for the wisdom of the Perl Monks concerning the following question:
Below is our testing code, mostly based on Perldoc, PerlEmbed and PerlCallstruct somestruct <----------- { int count; <--- This number could be from 25 to 25000 someotherstruct * pdata; <--- Obviously this number will match as +well } struct someotherstruct { <--- This structure can contain alot ... vectorstruct vSomething; vectorstruct vSomethingElse; float, int, char, and what not... } ...
Our perl script :************ // all the rest is temp : figuring this perl thing out... char * cpArguments[] = { "", "test1.pl" }; my_perl = perl_alloc(); ISNOTNULLRETURN(my_perl, "WinMain : NULL my_perl", "Error", -1); perl_construct(my_perl); PL_exit_flags |= PERL_EXIT_DESTRUCT_END; perl_parse(my_perl, NULL, 2, cpArguments, (char **)NULL); // run script // perl_run(my_perl); // run sub from script // char * cpArgumentsToSub[] = { NULL }; // call_argv("OnUpdate", G_DISCARD | G_NOARGS, cpArgumentsToSub); // run sub from script passing 2 vars into @_ (simple test). // ref http://www.apl.jhu.edu/Misc/Unix-info/perl/perlcall.html { SAFEMALLOCI(char, cpBuf, "WinMain : memory allocation failed", -1, + 1000); int a = 243; int b = 527; dSP; int count; SV * sva; //= NULL ? SV * svb; //= NULL ? ENTER; SAVETMPS; sva = sv_2mortal(newSViv(a)); svb = sv_2mortal(newSViv(b)); PUSHMARK(sp); XPUSHs(sva); XPUSHs(svb); PUTBACK; count = perl_call_pv("OnUpdate", G_DISCARD); if (count != 0) { croak("wtf\n"); BOX("wtf\n", "Error"); } int newa = SvIV(sva); int newb = SvIV(svb); sprintf (cpBuf, "A [ original = %d modified = %d ]\nB [ original = + %d modified = %d ]", a, newa, b, newb); BOX(cpBuf, "Debug"); FREETMPS; LEAVE; SAFEFREE(cpBuf); } perl_destruct(my_perl); perl_free(my_perl);
#!perl use strict; sub OnUpdate { ######################################## # get data ######################################## my ($a, $b) = @_; ######################################## # code using the names ######################################## $a = 5; $b = 3; ######################################## # send data ######################################## $_[0] = $a; $_[1] = $b; }
my $data = shift; for (my $i=0; $i<$data->count; $i++) { $data->pdata[$i]->vsomething->x = $whatever; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Embedding Perl / C++ structure question
by Joost (Canon) on Nov 28, 2007 at 18:58 UTC | |
by TheGeniuS (Novice) on Nov 28, 2007 at 20:26 UTC | |
by Joost (Canon) on Nov 28, 2007 at 21:00 UTC | |
by TheGeniuS (Novice) on Nov 28, 2007 at 22:08 UTC | |
by perlsyntax (Pilgrim) on Nov 28, 2007 at 22:57 UTC |