lua-users home
lua-l archive

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


Christophe Gimenez wrote:
> 
> Hello,
> Considere the following code, do you think these is a good way (or almost
> quite right) or do you think I was lucky not to have test.exe crashing ?
> Is there a way to simplify the whole operation ?
> void setObjectProperty(void)
> {
>         lua_Object params;
> 
>         params=lua_getparam(1);
> 
>         ((myObject*)(lua_getuserdata(params)))->setProperty(lua_getnumber(lua_g
> etparam(2)));
> }

You need to use tags.. A tag can asure you that parameter 1 is of type
myObject* otherwise your code will crash if setProperty is called with a
bogus value as parameter 1. So create a tag and assign that tag to the
value you are pushing in createNewObject and test that parameter 1 must
be of that tag type in setProperty.

/Erik