summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lauxlib.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/lauxlib.c b/lauxlib.c
index a828e612..698fba24 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.144 2005/08/15 14:12:32 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.145 2005/08/17 19:05:04 roberto Exp roberto $
3** Auxiliary functions for building Lua libraries 3** Auxiliary functions for building Lua libraries
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -130,18 +130,15 @@ LUALIB_API void luaL_getmetatable (lua_State *L, const char *tname) {
130 130
131 131
132LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { 132LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {
133 void *p = NULL; 133 void *p = lua_touserdata(L, ud);
134 if (lua_getmetatable(L, ud)) { 134 const char *tn;
135 const char *tn; 135 if (p == NULL || /* if is not a userdata? */
136 lua_rawget(L, LUA_REGISTRYINDEX); /* get registry[metatable] */ 136 !lua_getmetatable(L, ud) || /* has no metatable? */
137 tn = lua_tostring(L, -1); 137 (lua_rawget(L, LUA_REGISTRYINDEX), /* get registry[metatable] */
138 if (tn && (strcmp(tn, tname) == 0)) { 138 (tn = lua_tostring(L, -1)) == NULL) || /* metatable not registered? */
139 lua_pop(L, 1); 139 (strcmp(tn, tname) != 0)) /* or wrong? */
140 p = lua_touserdata(L, ud); 140 luaL_typerror(L, ud, tname); /* then error */
141 } 141 lua_pop(L, 1); /* remove registry[metatable] */
142 }
143 if (p == NULL)
144 luaL_typerror(L, ud, tname);
145 return p; 142 return p;
146} 143}
147 144