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 /lbaselib.c | |
parent | 81215cd59f58923ae9807d34f1dd46a51f400e4b (diff) | |
download | lua-405e3a4597d6f935a7ac224ce67dce660e69c7be.tar.gz lua-405e3a4597d6f935a7ac224ce67dce660e69c7be.tar.bz2 lua-405e3a4597d6f935a7ac224ce67dce660e69c7be.zip |
metatable always return some value
Diffstat (limited to 'lbaselib.c')
-rw-r--r-- | lbaselib.c | 15 |
1 files changed, 11 insertions, 4 deletions
@@ -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); |