diff options
Diffstat (limited to 'lbaselib.c')
-rw-r--r-- | lbaselib.c | 14 |
1 files changed, 5 insertions, 9 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.97 2002/08/08 20:08:41 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.98 2002/09/05 19:45:42 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 | */ |
@@ -109,14 +109,8 @@ static int luaB_getmetatable (lua_State *L) { | |||
109 | lua_pushnil(L); | 109 | lua_pushnil(L); |
110 | return 1; /* no metatable */ | 110 | return 1; /* no metatable */ |
111 | } | 111 | } |
112 | else { | 112 | luaL_getmetafield(L, 1, "__metatable"); |
113 | lua_pushliteral(L, "__metatable"); | 113 | return 1; /* returns either __metatable field (if present) or metatable */ |
114 | lua_rawget(L, -2); | ||
115 | if (lua_isnil(L, -1)) | ||
116 | lua_pop(L, 1); | ||
117 | /* otherwise returns metatable.__metatable */ | ||
118 | } | ||
119 | return 1; | ||
120 | } | 114 | } |
121 | 115 | ||
122 | 116 | ||
@@ -125,6 +119,8 @@ static int luaB_setmetatable (lua_State *L) { | |||
125 | luaL_check_type(L, 1, LUA_TTABLE); | 119 | luaL_check_type(L, 1, LUA_TTABLE); |
126 | luaL_arg_check(L, t == LUA_TNIL || t == LUA_TTABLE, 2, | 120 | luaL_arg_check(L, t == LUA_TNIL || t == LUA_TTABLE, 2, |
127 | "nil or table expected"); | 121 | "nil or table expected"); |
122 | if (luaL_getmetafield(L, 1, "__metatable")) | ||
123 | luaL_error(L, "cannot change a protected metatable"); | ||
128 | lua_settop(L, 2); | 124 | lua_settop(L, 2); |
129 | lua_setmetatable(L, 1); | 125 | lua_setmetatable(L, 1); |
130 | return 1; | 126 | return 1; |