----- Original Message -----
From: "Sisyphus" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Sunday, January 20, 2002 1:54 PM
Subject: Inline_Stack_Commands


> Hi,
> The code:
> #!perl -w
> use Inline C => <<'END_OF_C_CODE';
> void dumb ( int x, int y) {
>
> SV* c;
> SV* d;
>
> c = x * y;
> d = x + y;
>
> printf("%d\n", c);
> printf("%d\n", d);
>
> Inline_Stack_Vars;
> Inline_Stack_Reset;
> Inline_Stack_Push(c);
> Inline_Stack_Push(d);
> Inline_Stack_Done;
> /* Inline_Stack_Return(2); */
>
> }
>
> END_OF_C_CODE
>
> dumb(4, 28);
>
> ###################################

Sheeesh ! I still don't get that to work - but the following, more complex,
script works fine. (This second version is more in keeping with my actual
requirements - supply a variable-size list of integers, perform a
mathematical operation on each integer, and return each of the new values.)

Guess I don't have to worry about why the above script doesn't work :-)

But if someone has some illuminating words on the matter, I'd be very
pleased to receive them, as I'm not exactly sure what is going on - nor am I
sure as to what it is that I'm unsure of :-)

Anyway, fwiw, this works fine:

#!perl -w

use Inline C => <<'END_OF_C_CODE';

void dumb ( SV* x, ...)
    {
         Inline_Stack_Vars;
         int i; /* stack item number */
         int t;

Inline_Stack_Reset;

for (i = 0; i < Inline_Stack_Items; ++i) {
    t = SvIV(Inline_Stack_Item(i));

t *= 2;

Inline_Stack_Push(newSViv(t));

}


Inline_Stack_Done;
Inline_Stack_Return(i);
}

END_OF_C_CODE

my @try = (1,2,3,4,5,6);
my @ret = dumb(@try);
print "@ret\n";
#prints 2 4 6 8 10 12

Cheers,
Rob

Reply via email to