diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-08-17 16:05:04 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-08-17 16:05:04 -0300 |
commit | 2f2b4a42a95c7a96e5e16b74ba1167690fcd6231 (patch) | |
tree | 9a5ae551f28f24f6b9204c76cec49dc28386e16b /lauxlib.c | |
parent | 074352911f3fe3102e4103c2b7140d1cf3d48492 (diff) | |
download | lua-2f2b4a42a95c7a96e5e16b74ba1167690fcd6231.tar.gz lua-2f2b4a42a95c7a96e5e16b74ba1167690fcd6231.tar.bz2 lua-2f2b4a42a95c7a96e5e16b74ba1167690fcd6231.zip |
luaL_checkudata raises an error if value is not correct
(like other luaL_check functions)
Diffstat (limited to 'lauxlib.c')
-rw-r--r-- | lauxlib.c | 25 |
1 files changed, 13 insertions, 12 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.143 2005/08/10 18:47:09 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.144 2005/08/15 14:12:32 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,19 @@ LUALIB_API void luaL_getmetatable (lua_State *L, const char *tname) { | |||
130 | 130 | ||
131 | 131 | ||
132 | LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { | 132 | LUALIB_API void *luaL_checkudata (lua_State *L, int ud, const char *tname) { |
133 | const char *tn; | 133 | void *p = NULL; |
134 | if (!lua_getmetatable(L, ud)) return NULL; /* no metatable? */ | 134 | if (lua_getmetatable(L, ud)) { |
135 | lua_rawget(L, LUA_REGISTRYINDEX); /* get registry[metatable] */ | 135 | const char *tn; |
136 | tn = lua_tostring(L, -1); | 136 | lua_rawget(L, LUA_REGISTRYINDEX); /* get registry[metatable] */ |
137 | if (tn && (strcmp(tn, tname) == 0)) { | 137 | tn = lua_tostring(L, -1); |
138 | lua_pop(L, 1); | 138 | if (tn && (strcmp(tn, tname) == 0)) { |
139 | return lua_touserdata(L, ud); | 139 | lua_pop(L, 1); |
140 | } | 140 | p = lua_touserdata(L, ud); |
141 | else { | 141 | } |
142 | lua_pop(L, 1); | ||
143 | return NULL; | ||
144 | } | 142 | } |
143 | if (p == NULL) | ||
144 | luaL_typerror(L, ud, tname); | ||
145 | return p; | ||
145 | } | 146 | } |
146 | 147 | ||
147 | 148 | ||