diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-03-27 09:49:53 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2002-03-27 09:49:53 -0300 |
commit | 405e3a4597d6f935a7ac224ce67dce660e69c7be (patch) | |
tree | 8c1914067e66e00a339bd1a25ec785e33186ede3 | |
parent | 81215cd59f58923ae9807d34f1dd46a51f400e4b (diff) | |
download | lua-405e3a4597d6f935a7ac224ce67dce660e69c7be.tar.gz lua-405e3a4597d6f935a7ac224ce67dce660e69c7be.tar.bz2 lua-405e3a4597d6f935a7ac224ce67dce660e69c7be.zip |
metatable always return some value
-rw-r--r-- | lapi.c | 14 | ||||
-rw-r--r-- | lbaselib.c | 15 | ||||
-rw-r--r-- | lua.h | 4 |
3 files changed, 23 insertions, 10 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 1.179 2002/03/20 12:51:29 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 1.180 2002/03/26 20:46:10 roberto Exp roberto $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -400,9 +400,10 @@ LUA_API void lua_newtable (lua_State *L) { | |||
400 | } | 400 | } |
401 | 401 | ||
402 | 402 | ||
403 | LUA_API void lua_getmetatable (lua_State *L, int objindex) { | 403 | LUA_API int lua_getmetatable (lua_State *L, int objindex) { |
404 | StkId obj; | 404 | StkId obj; |
405 | Table *mt; | 405 | Table *mt; |
406 | int res; | ||
406 | lua_lock(L); | 407 | lua_lock(L); |
407 | obj = luaA_indexAcceptable(L, objindex); | 408 | obj = luaA_indexAcceptable(L, objindex); |
408 | switch (ttype(obj)) { | 409 | switch (ttype(obj)) { |
@@ -415,12 +416,17 @@ LUA_API void lua_getmetatable (lua_State *L, int objindex) { | |||
415 | default: | 416 | default: |
416 | mt = hvalue(defaultmeta(L)); | 417 | mt = hvalue(defaultmeta(L)); |
417 | } | 418 | } |
418 | if (mt == hvalue(defaultmeta(L))) | 419 | if (mt == hvalue(defaultmeta(L))) { |
419 | setnilvalue(L->top); | 420 | setnilvalue(L->top); |
420 | else | 421 | res = 0; |
422 | } | ||
423 | else { | ||
421 | sethvalue(L->top, mt); | 424 | sethvalue(L->top, mt); |
425 | res = 1; | ||
426 | } | ||
422 | api_incr_top(L); | 427 | api_incr_top(L); |
423 | lua_unlock(L); | 428 | lua_unlock(L); |
429 | return res; | ||
424 | } | 430 | } |
425 | 431 | ||
426 | 432 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.59 2002/02/14 21:42:22 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.60 2002/03/20 12:54:08 roberto Exp roberto $ |
3 | ** Basic library | 3 | ** Basic library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -120,11 +120,18 @@ static int luaB_error (lua_State *L) { | |||
120 | 120 | ||
121 | 121 | ||
122 | static int luaB_metatable (lua_State *L) { | 122 | static int luaB_metatable (lua_State *L) { |
123 | luaL_check_type(L, 1, LUA_TTABLE); | 123 | luaL_check_any(L, 1); |
124 | if (lua_isnone(L, 2)) | 124 | if (lua_isnone(L, 2)) { |
125 | lua_getmetatable(L, 1); | 125 | if (lua_getmetatable(L, 1)) { |
126 | lua_pushliteral(L, "__metatable"); | ||
127 | lua_rawget(L, -2); | ||
128 | if (lua_isnil(L, -1)) | ||
129 | lua_pop(L, 1); | ||
130 | } | ||
131 | } | ||
126 | else { | 132 | else { |
127 | int t = lua_type(L, 2); | 133 | int t = lua_type(L, 2); |
134 | luaL_check_type(L, 1, LUA_TTABLE); | ||
128 | luaL_arg_check(L, t == LUA_TNIL || t == LUA_TTABLE, 2, "nil/table expected"); | 135 | luaL_arg_check(L, t == LUA_TNIL || t == LUA_TTABLE, 2, "nil/table expected"); |
129 | lua_settop(L, 2); | 136 | lua_settop(L, 2); |
130 | lua_setmetatable(L, 1); | 137 | lua_setmetatable(L, 1); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.h,v 1.122 2002/03/07 18:15:10 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.123 2002/03/18 18:18:35 roberto Exp roberto $ |
3 | ** Lua - An Extensible Extension Language | 3 | ** Lua - An Extensible Extension Language |
4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil | 4 | ** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil |
5 | ** e-mail: info@lua.org | 5 | ** e-mail: info@lua.org |
@@ -152,7 +152,7 @@ LUA_API void lua_gettable (lua_State *L, int index); | |||
152 | LUA_API void lua_rawget (lua_State *L, int index); | 152 | LUA_API void lua_rawget (lua_State *L, int index); |
153 | LUA_API void lua_rawgeti (lua_State *L, int index, int n); | 153 | LUA_API void lua_rawgeti (lua_State *L, int index, int n); |
154 | LUA_API void lua_newtable (lua_State *L); | 154 | LUA_API void lua_newtable (lua_State *L); |
155 | LUA_API void lua_getmetatable (lua_State *L, int objindex); | 155 | LUA_API int lua_getmetatable (lua_State *L, int objindex); |
156 | 156 | ||
157 | 157 | ||
158 | /* | 158 | /* |