summaryrefslogtreecommitdiff
path: root/lauxlib.c
diff options
context:
space:
mode:
Diffstat (limited to 'lauxlib.c')
-rw-r--r--lauxlib.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/lauxlib.c b/lauxlib.c
index 8aff27ca..402dcd80 100644
--- a/lauxlib.c
+++ b/lauxlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lauxlib.c,v 1.157 2005/12/29 15:32:11 roberto Exp roberto $ 2** $Id: lauxlib.c,v 1.158 2006/01/16 12:42:21 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*/
@@ -123,11 +123,17 @@ LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) {
123 123
124LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { 124LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) {
125 void *p = lua_touserdata(L, ud); 125 void *p = lua_touserdata(L, ud);
126 lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */ 126 if (p != NULL) { /* value is a userdata? */
127 if (p == NULL || !lua_getmetatable(L, ud) || !lua_rawequal(L, -1, -2)) 127 if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
128 luaL_typerror(L, ud, tname); 128 lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */
129 lua_pop(L, 2); /* remove both metatables */ 129 if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */
130 return p; 130 lua_pop(L, 2); /* remove both metatables */
131 return p;
132 }
133 }
134 }
135 luaL_typerror(L, ud, tname); /* else error */
136 return NULL; /* to avoid warnings */
131} 137}
132 138
133 139