diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-12-02 11:25:57 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-12-02 11:25:57 -0200 |
| commit | e2feb886d688bfc96697b634f03e7cc319234139 (patch) | |
| tree | f7fb2a6918a997a16f587d22bdb8c17def01114e | |
| parent | 5999e14ad90a7df3834f4141a52eac1f12cdfc10 (diff) | |
| download | lua-e2feb886d688bfc96697b634f03e7cc319234139.tar.gz lua-e2feb886d688bfc96697b634f03e7cc319234139.tar.bz2 lua-e2feb886d688bfc96697b634f03e7cc319234139.zip | |
macro 'luaL_getmetatable' seems more appropriate when getting
metatables in registry
| -rw-r--r-- | lauxlib.c | 6 |
1 files changed, 3 insertions, 3 deletions
| @@ -1,5 +1,5 @@ | |||
| 1 | /* | 1 | /* |
| 2 | ** $Id: lauxlib.c,v 1.237 2011/11/29 15:55:08 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.238 2011/11/30 12:58:57 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 | */ |
| @@ -269,7 +269,7 @@ LUALIB_API int luaL_execresult (lua_State *L, int stat) { | |||
| 269 | */ | 269 | */ |
| 270 | 270 | ||
| 271 | LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) { | 271 | LUALIB_API int luaL_newmetatable (lua_State *L, const char *tname) { |
| 272 | lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get registry.name */ | 272 | luaL_getmetatable(L, tname); /* try to get metatable */ |
| 273 | if (!lua_isnil(L, -1)) /* name already in use? */ | 273 | if (!lua_isnil(L, -1)) /* name already in use? */ |
| 274 | return 0; /* leave previous value on top, but return 0 */ | 274 | return 0; /* leave previous value on top, but return 0 */ |
| 275 | lua_pop(L, 1); | 275 | lua_pop(L, 1); |
| @@ -290,7 +290,7 @@ LUALIB_API void *luaL_testudata (lua_State *L, int ud, const char *tname) { | |||
| 290 | void *p = lua_touserdata(L, ud); | 290 | void *p = lua_touserdata(L, ud); |
| 291 | if (p != NULL) { /* value is a userdata? */ | 291 | if (p != NULL) { /* value is a userdata? */ |
| 292 | if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ | 292 | if (lua_getmetatable(L, ud)) { /* does it have a metatable? */ |
| 293 | lua_getfield(L, LUA_REGISTRYINDEX, tname); /* get correct metatable */ | 293 | luaL_getmetatable(L, tname); /* get correct metatable */ |
| 294 | if (!lua_rawequal(L, -1, -2)) /* not the same? */ | 294 | if (!lua_rawequal(L, -1, -2)) /* not the same? */ |
| 295 | p = NULL; /* value is a userdata with wrong metatable */ | 295 | p = NULL; /* value is a userdata with wrong metatable */ |
| 296 | lua_pop(L, 2); /* remove both metatables */ | 296 | lua_pop(L, 2); /* remove both metatables */ |
