Package: tolua++5.1-dev
Severity: normal

If I declare a function in a *.pkg file like this:

void fun(lua_State *state, int numbers[42]);

then tolua++ generates the following stub for Lua to call:

/* function: fun */
#ifndef TOLUA_DISABLE_tolua_huh_fun00
static int tolua_huh_fun00(lua_State* tolua_S)
{
#ifndef TOLUA_RELEASE
 tolua_Error tolua_err;
 if (
     !tolua_istable(tolua_S,1,0,&tolua_err) ||
     !tolua_isnoobj(tolua_S,2,&tolua_err)
 )
  goto tolua_lerror;
 else
#endif
 {
  lua_State* state =  tolua_S;
  int numbers[42];
  {
#ifndef TOLUA_RELEASE
   if (!tolua_isnumberarray(tolua_S,2,42,0,&tolua_err))
    goto tolua_lerror;
   else
#endif
   {
    int i;
    for(i=0; i<42;i++)
    numbers[i] = ((int)  tolua_tofieldnumber(tolua_S,2,i+1,0));
   }
  }
  {
   fun(state,numbers);
  }
  {
   int i;
   for(i=0; i<42;i++)
    tolua_pushfieldnumber(tolua_S,2,i+1,(lua_Number) numbers[i]);
  }
 }
 return 0;
#ifndef TOLUA_RELEASE
 tolua_lerror:
 tolua_error(tolua_S,"#ferror in function 'fun'.",&tolua_err);
 return 0;
#endif
}
#endif //#ifndef TOLUA_DISABLE

In th e tolua_isnumberarray, tolua_tofieldnumber, and
tolua_pushfieldnumber calls, the second argument is wrong.
It should be 1 rather than 2, because "numbers" is the first
parameter in the Lua stack, even though it is the second
parameter of the C++ function.  Note that the generated code
has previously called tolua_istable(tolua_S,1,0,&tolua_err)
with the correct stack index.

If I move the lua_State * parameter to the end of the list,
then "numbers" is the first parameter in both Lua and C++,
and tolua++ generates correct code.

-- System Information:
Debian Release: 6.0
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: amd64 (x86_64)

Kernel: Linux 2.6.32-5-amd64 (SMP w/2 CPU cores)
Locale: LANG=fi_FI.UTF-8, LC_CTYPE=fi_FI.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Attachment: pgpi55Fib7Gfr.pgp
Description: PGP signature

Reply via email to