lua-users home
lua-l archive

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


It was thus said that the Great Laurent FAILLIE once stated:
> Thanks Sean,
> I've converted to pointer to pointer and it's working fine.
> 
> > Some random comments:  you don't need checkSelFIFO()---luaL_checkudata()
> > will do what you want.
> 
> It's only to embbed type checking with luaL_argcheck().As per my reading,
> luaL_checkudata() only returns a NULL in case of check failure, isn't it ?
> (it would be more efficient to be an inline function ... and it will be).

  It takes a close reading of the manual, but luaL_checkudata() has an
indicator (described in section 4.8 of the Lua 5.3 manual) of:

	[-0,+0,v]

which indicates it can intentionally throw an error, and yes, if the given
item at the index isn't a userdata with the proper type (checked by the
metatable of the given name), it throws an error.  If it returns, it will
never return a NULL value.

> > Second, DO NOT USE assert() TO CHECK THE RETURN CODE> FOR FUNCTIONS! 
> 
> It is only by laziness :) I have done that for very small allocations: if
> they fail, in any case, the application is close to crash facing a severe
> starvation of resources.

  Best to either return a Lua nil, or throw a Lua error:

	if (ptr == NULL)
	  return luaL_error(L,"OUT OF MEMORY!");

  -spc