On Fri, 4 Feb 2005 16:30:32 +0900, Asbj?rn Reglund Thorsen
<asbjoert / ifi.uio.no> wrote:

> This is what I tried, but did not work:
> 
> %typemap(out) int &{      //C->Ruby, Back to Ruby int object
>    long *n = (long *) $1;
>    $result = INT2NUM(*n);
> }

This one won't generate a compiler error (well, it didn't for me) but
it's dangerous to cast the return value, which is a pointer-to-int, to
a pointer-to-long. Here's a better version of this typemap:

    %typemap(out) int & {
        $result = INT2NUM(*$1);
    }

> %typemap(in) int &{       //Ruby->C, From Ruby integer to C long
>    $1 = NUM2INT($input);
> }

OK, this is the one that generated the compiler error you saw. Here's
a corrected version:

    %typemap(in) int & (int tmp) {
        tmp = NUM2INT($input);
        $1 = &tmp;
    }

Hope this helps,

Lyle