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] |
hi,
in that case how wld the perl subroutine demarcate
the two arrays arr1 & arr2. ie if we have arr1=(1,2)
and arr2=(3,4) how wld the perl subroutine know that arr1's
contents ends at 2 and arr2 ends at 4 as i would be doing
only XPUSH of 1,2,3,4 before calling the sub through perl_call_pv.
any help would be greatly appreciated .
thank you
ragu
| [reply] |