fancier code ;)

This commit is contained in:
Roberto Ierusalimschy 2005-08-17 17:09:31 -03:00
parent 2f2b4a42a9
commit 68548a02d3
1 changed files with 10 additions and 13 deletions

View File

@ -1,5 +1,5 @@
/* /*
** $Id: lauxlib.c,v 1.144 2005/08/15 14:12:32 roberto Exp roberto $ ** $Id: lauxlib.c,v 1.145 2005/08/17 19:05:04 roberto Exp roberto $
** Auxiliary functions for building Lua libraries ** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h ** See Copyright Notice in lua.h
*/ */
@ -130,18 +130,15 @@ LUALIB_API void luaL_getmetatable (lua_State *L, const char *tname) {
LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {
void *p = NULL; void *p = lua_touserdata(L, ud);
if (lua_getmetatable(L, ud)) { const char *tn;
const char *tn; if (p == NULL || /* if is not a userdata? */
lua_rawget(L, LUA_REGISTRYINDEX); /* get registry[metatable] */ !lua_getmetatable(L, ud) || /* has no metatable? */
tn = lua_tostring(L, -1); (lua_rawget(L, LUA_REGISTRYINDEX), /* get registry[metatable] */
if (tn && (strcmp(tn, tname) == 0)) { (tn = lua_tostring(L, -1)) == NULL) || /* metatable not registered? */
lua_pop(L, 1); (strcmp(tn, tname) != 0)) /* or wrong? */
p = lua_touserdata(L, ud); luaL_typerror(L, ud, tname); /* then error */
} lua_pop(L, 1); /* remove registry[metatable] */
}
if (p == NULL)
luaL_typerror(L, ud, tname);
return p; return p;
} }