SIWG 1.3.31 and Lua 5.1.3, typemap(out) being ignored?

View: New views
4 Messages — Rating Filter:   Alert me  

SIWG 1.3.31 and Lua 5.1.3, typemap(out) being ignored?

by Aaron Saarela :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm using SWIG 1.3.31 to generate wrappers for Lua 5.1.3 with the LNum patch.
LNum adds support for 64-bit integers and adds 'lua_pushinteger' and
'lua_totinteger' helper functions to work with them. I defined a typemap to
handle these explicitly as follows:

%typemap(in) Int64
{
   $1 = (Int64)lua_tointeger(L, $argnum)
}

%typemap(out) Int64
{
    lua_pushinteger(L, $1); SWIG_Arg++;
}

The 'in' typemap generates code I'd expect.

The 'out' typemap seems to ignore my typemap altogether and generates default
code. This has the unfortunate consequence of 'converting' my Int64 to a
double.

e.g. I have a function 'Int64 MyFunction(Int64 val)'. The generated SWIG
wrapper looks like:

static int _wrap_MyFunction(lua_State* L) {
  int SWIG_arg = -1;
  Int64 arg1;
  Int64 result;
 
  SWIG_check_num_args("MyFunction",1,1)
  arg1 = (Int64)lua_tointeger(L, 1);

  result = MyFunction(arg1);

  SWIG_arg=0;
  lua_pushnumber(L, (lua_Number) result); SWIG_arg++;
  return SWIG_arg;
 
  if(0) SWIG_fail;
 
fail:
  lua_error(L);
  return SWIG_arg;
}


The work around I've come up with is to %ignore all the functions that return
Int64 and define them myself using %native. This is really ugly and adding up
to a lot of custom SWIG wrapper functions. It also means I need to be
particularly careful going forward to write custom wrappers for any new
functions that need to return Int64 values.

Is there a way to get SWIG to generate 'out' code using my typemap?

Thanks,
-Aaron


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: SIWG 1.3.31 and Lua 5.1.3, typemap(out) being ignored?

by wsfulton :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Aaron Saarela wrote:

> I'm using SWIG 1.3.31 to generate wrappers for Lua 5.1.3 with the LNum patch.
> LNum adds support for 64-bit integers and adds 'lua_pushinteger' and
> 'lua_totinteger' helper functions to work with them. I defined a typemap to
> handle these explicitly as follows:
>
> %typemap(in) Int64
> {
>    $1 = (Int64)lua_tointeger(L, $argnum)
> }
>
> %typemap(out) Int64
> {
>     lua_pushinteger(L, $1); SWIG_Arg++;
> }
>
> The 'in' typemap generates code I'd expect.
>
> The 'out' typemap seems to ignore my typemap altogether and generates default
> code. This has the unfortunate consequence of 'converting' my Int64 to a
> double.
>
> e.g. I have a function 'Int64 MyFunction(Int64 val)'. The generated SWIG
> wrapper looks like:
>
> static int _wrap_MyFunction(lua_State* L) {
>   int SWIG_arg = -1;
>   Int64 arg1;
>   Int64 result;
>  
>   SWIG_check_num_args("MyFunction",1,1)
>   arg1 = (Int64)lua_tointeger(L, 1);
>
>   result = MyFunction(arg1);
>
>   SWIG_arg=0;
>   lua_pushnumber(L, (lua_Number) result); SWIG_arg++;
>   return SWIG_arg;
>  
>   if(0) SWIG_fail;
>  
> fail:
>   lua_error(L);
>   return SWIG_arg;
> }
>
>
> The work around I've come up with is to %ignore all the functions that return
> Int64 and define them myself using %native. This is really ugly and adding up
> to a lot of custom SWIG wrapper functions. It also means I need to be
> particularly careful going forward to write custom wrappers for any new
> functions that need to return Int64 values.
>
> Is there a way to get SWIG to generate 'out' code using my typemap?
>
Does the problem still exist with swig-1.3.35? If so please raise a bug
report as this would be a pretty fundamental problem if you are using
typemaps correctly.

William

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Parent Message unknown Re: SIWG 1.3.31 and Lua 5.1.3, typemap(out) being ignored?

by mark gossage :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


> I'm using SWIG 1.3.31 to generate wrappers for Lua
> 5.1.3 with the LNum patch.
> LNum adds support for 64-bit integers and adds
> 'lua_pushinteger' and
> 'lua_totinteger' helper functions to work with
> them. I defined a typemap to
> handle these explicitly as follows:
>
> %typemap(in) Int64
> {
>    $1 = (Int64)lua_tointeger(L, $argnum)
> }
>
> %typemap(out) Int64
> {
>     lua_pushinteger(L, $1); SWIG_Arg++;
> }
>
> The 'in' typemap generates code I'd expect.
>
> The 'out' typemap seems to ignore my typemap
> altogether and generates default
> code. This has the unfortunate consequence of
> 'converting' my Int64 to a
> double.
>
> e.g. I have a function 'Int64 MyFunction(Int64
> val)'. The generated SWIG
> wrapper looks like:

Hello Aaron,
Are you sure? I don't have any problems with it.

I am using the latest SWIG 1.3.35. The following code compiles fine:

=====================
%typemap(in,checkfn="lua_isnumber") __int64
{
   $1 = (__int64)lua_tointeger(L, $argnum);
}

%typemap(out) __int64
{
    lua_pushinteger(L, $1); SWIG_arg++;
}

%inline %{
__int64 MyFunction(__int64 val){return val;}
%}
=====================
(I don't have the LNUM patch, so I just used the __int64 instead).
Can you check this code on your machine.

The other stunt you can do is just:
%apply long {Int64};
Which tells SWIG to treat a Int64 in a similar way to a long (which should work).

If there is still a problem, try getting a later copy of SWIG and let me know.
Regards,
Mark


      __________________________________________________________
Sent from Yahoo! Mail.
A Smarter Email http://uk.docs.yahoo.com/nowyoucan.html

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user

Re: SIWG 1.3.31 and Lua 5.1.3, typemap(out) being ignored?

by Aaron Saarela :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Thanks for the hint. After updating to 1.3.35 the problem went away.

>-----Original Message-----
>From: William Fulton [mailto:william@...] On Behalf Of
>William S Fulton
>Sent: Thursday, June 12, 2008 4:25 PM
>To: Aaron Saarela
>Cc: swig-user@...
>Subject: Re: [Swig-user] SIWG 1.3.31 and Lua 5.1.3, typemap(out) being
>ignored?
>>
>Does the problem still exist with swig-1.3.35? If so please raise a bug
>report as this would be a pretty fundamental problem if you are using
>typemaps correctly.
>
>William


-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://sourceforge.net/services/buy/index.php
_______________________________________________
Swig-user mailing list
Swig-user@...
https://lists.sourceforge.net/lists/listinfo/swig-user
LightInTheBox - Buy quality products at wholesale price