lua-users home
lua-l archive

A modest suggestion for the Lua 5.2 C API: luaL_checklightudata(L, narg)

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


/* to go in src/lauxlib.c */
LUALIB_API void *
checklightudata(lua_State *L, int narg)
{
 if (lua_islightuserdata(L, narg))
 luaL_typerror(L, narg, "lightuserdata");
 return lua_topointer(L, narg);
}
I felt that this was the only function missing from the luaL_check*()
functions. The objective is to assert that a certain stack index is
lightuserdata and generate a type error if it isn't, otherwise return
the void * contained.
NOTE: I could not use tag_error() for consistency with the other
luaL_check*() functions. If tag_error() were used and this were
called on an index containing userdata (not lightuserdata) it would
generate an error like this:
location: bad argument narg to 'func' (userdata expected, got userdata)
Please and thank you, Brasil :x

AltStyle によって変換されたページ (->オリジナル) /