commit eb8ac6e2a0eb84f3849d5bd50fd3bd2adb903521
parent b1203e036dceeb57947e88793cc7f7eb238542a0
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Thu, 12 Jun 2008 11:37:04 -0300
'luaL_testudata' does not leave garbage on the stack in case of failure
Diffstat:
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/lauxlib.c b/lauxlib.c
@@ -1,5 +1,5 @@
/*
-** $Id: lauxlib.c,v 1.175 2008/01/03 17:07:59 roberto Exp roberto $
+** $Id: lauxlib.c,v 1.176 2008/01/17 16:24:30 roberto Exp roberto $
** Auxiliary functions for building Lua libraries
** See Copyright Notice in lua.h
*/
@@ -165,13 +165,13 @@ LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) {
if (p != NULL) { /* value is a userdata? */
if (lua_getmetatable(L, ud)) { /* does it have a metatable? */
lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */
- if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */
- lua_pop(L, 2); /* remove both metatables */
- return p;
- }
+ if (!lua_rawequal(L, -1, -2)) /* not the same? */
+ p = NULL; /* value is a userdata with wrong metatable */
+ lua_pop(L, 2); /* remove both metatables */
+ return p;
}
}
- return NULL; /* value is not a userdata of the proper type */
+ return NULL; /* value is not a userdata with a metatable */
}