lua-users home
lua-l archive

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


tolua relies on the assumption you are using the
Lua syntactic sugar to call a method.

if you write: obj:method (...), the 'self' parameter is implicitly passed.

but you are right that one can cause problems writing
obj.method(another_obj,...)

thanks for pointing this out.

-- w

Eric Ries wrote:

> Let's take a bit of toLua generated code as follows:
>
> /* set function: newGoalOri of class  SuiGoalOrientationOutput */
> static int toluaI_set_Sui_SuiGoalOrientationOutput_newGoalOri(lua_State*
> tolua_S)
> {
>   SuiGoalOrientationOutput* self = (SuiGoalOrientationOutput*)
> tolua_getusertype(tolua_S,1,0);
>  if (!self) tolua_error(tolua_S,"invalid 'self' in accessing variable
> 'newGoalOri' in func toluaI_set_Sui_SuiGoalOrientationOutput_newGoalOri");
>  if (!tolua_istype(tolua_S,2,tolua_tag(tolua_S,"Ori"),0))
>  tolua_error(tolua_S,"#vinvalid type in variable assignment. in func
> toluaI_set_Sui_SuiGoalOrientationOutput_newGoalOri");
>   self->newGoalOri = *((CartesianOri*)  tolua_getusertype(tolua_S,2,0));
>  return 0;
> }
>
> Now, notice that the "self" parameter is cast to a SuiGoalOrientationOutput
> pointer without any checking that the first parameter is of the right type.
> So it seems to me that it would be possible to contrive some Lua code that
> could cause this code to violate the type-safeness of toLua.
>
> Am I right? Seems to me like a simple call to tolua_tag() before
> tolua_getusertype() would do it...
>
> Eric