lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]



Juan Pablo Sousa wrote:

> I don't know if you are already aware of this problem:
> when I have to overloaded functions that has some optional parameters tolua
> soemtimes can't find the correct function to call if I don't provide all the
> parameters. for example:
>
> I have
>
> class my_class {
> void some_function(char *);
> void some_function(int x,int y,int w=80,int h=80);
>
> }
>
> tolua generates something like this for the second one:
>
>  static ...... my_class_some_function01(lua_State *tolua_S)
> {
>         if (
>         !tolua_istype(tolua_S,2,LUA_TNUMBER,0) ||
>         !tolua_istype(tolua_S,3,LUA_TNUMBER,0) ||
>         !tolua_istype(tolua_S,4,LUA_TNUMBER,0) ||
>         !tolua_istype(tolua_S,5,LUA_TNUMBER,0) )
>         //call the second one
>         else
>         //call the first one
> }

that's not true. tolua generates two different lines:

        !tolua_istype(tolua_S,4,LUA_TNUMBER,1) ||
        !tolua_istype(tolua_S,5,LUA_TNUMBER,1) )

notice the forth parameter with value 1, meaning there's a
default value for them.


> but if I call
> some_function(10,10) it will try to execute the one with char * with an
> error
>

it should work fine.
check your code again, please, and
let me know if the problem persists.

-- w