diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2008-06-12 11:37:27 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2008-06-12 11:37:27 -0300 |
| commit | eb8ac6e2a0eb84f3849d5bd50fd3bd2adb903521 (patch) | |
| tree | d56734785f65808016c82ed320c09d0eff875322 | |
| parent | b1203e036dceeb57947e88793cc7f7eb238542a0 (diff) | |
| download | lua-eb8ac6e2a0eb84f3849d5bd50fd3bd2adb903521.tar.gz lua-eb8ac6e2a0eb84f3849d5bd50fd3bd2adb903521.tar.bz2 lua-eb8ac6e2a0eb84f3849d5bd50fd3bd2adb903521.zip | |
'luaL_testudata' does not leave garbage on the stack in case of failure
| -rw-r--r-- | lauxlib.c | 12 |
1 files changed, 6 insertions, 6 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.c,v 1.175 2008/01/03 17:07:59 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.176 2008/01/17 16:24:30 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 | */ |
| @@ -165,13 +165,13 @@ LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) { | |||
| 165 | if (p != NULL) { /* value is a userdata? */ | 165 | if (p != NULL) { /* value is a userdata? */ |
| 166 | if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ | 166 | if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ |
| 167 | lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */ | 167 | lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */ |
| 168 | if (lua_rawequal(L, -1, -2)) { /* does it have the correct mt? */ | 168 | if (!lua_rawequal(L, -1, -2)) /* not the same? */ |
| 169 | lua_pop(L, 2); /* remove both metatables */ | 169 | p = NULL; /* value is a userdata with wrong metatable */ |
| 170 | return p; | 170 | lua_pop(L, 2); /* remove both metatables */ |
| 171 | } | 171 | return p; |
| 172 | } | 172 | } |
| 173 | } | 173 | } |
| 174 | return NULL; /* value is not a userdata of the proper type */ | 174 | return NULL; /* value is not a userdata with a metatable */ |
| 175 | } | 175 | } |
| 176 | 176 | ||
| 177 | 177 | ||
