[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: A modest suggestion for the Lua 5.2 C API: luaL_checklightudata(L, narg)
- From: Sir Pogsalot <sir.pogsalot@...>
- Date: Fri, 14 Dec 2012 14:01:23 +0000
/* 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