You can't XPUSH an array, you have to XPUSH a reference to the array or just XPUSH all of the elements onto the stack. If you want to emulate my_function(@array), then don't build an array, just XPUSH the elements onto the Perl stack.
| [reply] |
I am trying to implement a provision by which any perl sub
cld be called from C ,so i may want to emulate something like
my_function("string1",@arr1,@arr2,"string2",@arr3,...).
Right now i do XPUSHs(sv_2mortal...) for the string1 then
create arr1 by newAV() & then do av_push(arr1..) of SV's within
arr1 & then XPUSH(arr1) (which is a ptr as newAV returns AV*)
...but this sequence doesn't help.
( also i tried with/without PUTBACK;av_push();SPAGAIN; as
i saw source code for av_push() uses dSP; and does some
SVTIED push of SV's into stack. but neither of them helped)
Is there something wrong in my sequence.Please do reply.
thank you
ragu
| [reply] |
To emulate
my_function("string1",@arr1,@arr2,"string2",@arr3)
you just need to XPUSH the string, then XPUSH each of the
elements of @arr1 (you don't need to build an array), then
XPUSH each of the elements of @arr2, then XPUSH the next
string, then XPUSH each of the elemnts of @arr3.
That is, in this code:
my @arr1= qw(A few things);
my @arr2= qw(Two vals);
my @arr3= (1,2,3);
my_function("string1",@arr1,@arr2,"string2",@arr3);
my_function(qw(string1 A few things Two vals string2),1,2,3);
the last two lines are the same (unless my_function has
a prototype).
-
tye
(but my friends call me "Tye") | [reply] [d/l] [select] |