diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-08-17 17:09:31 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2005-08-17 17:09:31 -0300 |
commit | 68548a02d39861176b59f58be93315b51eafdbe2 (patch) | |
tree | b0744010637022a03de66b570cb9a5abbeb05a31 | |
parent | 2f2b4a42a95c7a96e5e16b74ba1167690fcd6231 (diff) | |
download | lua-68548a02d39861176b59f58be93315b51eafdbe2.tar.gz lua-68548a02d39861176b59f58be93315b51eafdbe2.tar.bz2 lua-68548a02d39861176b59f58be93315b51eafdbe2.zip |
fancier code ;)
-rw-r--r-- | lauxlib.c | 23 |
1 files changed, 10 insertions, 13 deletions
@@ -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 | ||
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 | 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 | ||