mirror of
https://github.com/lua/lua
synced 2025-04-17 02:12:54 +03:00
metatable always return some value
This commit is contained in:
parent
81215cd59f
commit
405e3a4597
14
lapi.c
14
lapi.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lapi.c,v 1.179 2002/03/20 12:51:29 roberto Exp roberto $
|
** $Id: lapi.c,v 1.180 2002/03/26 20:46:10 roberto Exp roberto $
|
||||||
** Lua API
|
** Lua API
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -400,9 +400,10 @@ LUA_API void lua_newtable (lua_State *L) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
LUA_API void lua_getmetatable (lua_State *L, int objindex) {
|
LUA_API int lua_getmetatable (lua_State *L, int objindex) {
|
||||||
StkId obj;
|
StkId obj;
|
||||||
Table *mt;
|
Table *mt;
|
||||||
|
int res;
|
||||||
lua_lock(L);
|
lua_lock(L);
|
||||||
obj = luaA_indexAcceptable(L, objindex);
|
obj = luaA_indexAcceptable(L, objindex);
|
||||||
switch (ttype(obj)) {
|
switch (ttype(obj)) {
|
||||||
@ -415,12 +416,17 @@ LUA_API void lua_getmetatable (lua_State *L, int objindex) {
|
|||||||
default:
|
default:
|
||||||
mt = hvalue(defaultmeta(L));
|
mt = hvalue(defaultmeta(L));
|
||||||
}
|
}
|
||||||
if (mt == hvalue(defaultmeta(L)))
|
if (mt == hvalue(defaultmeta(L))) {
|
||||||
setnilvalue(L->top);
|
setnilvalue(L->top);
|
||||||
else
|
res = 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
sethvalue(L->top, mt);
|
sethvalue(L->top, mt);
|
||||||
|
res = 1;
|
||||||
|
}
|
||||||
api_incr_top(L);
|
api_incr_top(L);
|
||||||
lua_unlock(L);
|
lua_unlock(L);
|
||||||
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
15
lbaselib.c
15
lbaselib.c
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lbaselib.c,v 1.59 2002/02/14 21:42:22 roberto Exp roberto $
|
** $Id: lbaselib.c,v 1.60 2002/03/20 12:54:08 roberto Exp roberto $
|
||||||
** Basic library
|
** Basic library
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
@ -120,11 +120,18 @@ static int luaB_error (lua_State *L) {
|
|||||||
|
|
||||||
|
|
||||||
static int luaB_metatable (lua_State *L) {
|
static int luaB_metatable (lua_State *L) {
|
||||||
luaL_check_type(L, 1, LUA_TTABLE);
|
luaL_check_any(L, 1);
|
||||||
if (lua_isnone(L, 2))
|
if (lua_isnone(L, 2)) {
|
||||||
lua_getmetatable(L, 1);
|
if (lua_getmetatable(L, 1)) {
|
||||||
|
lua_pushliteral(L, "__metatable");
|
||||||
|
lua_rawget(L, -2);
|
||||||
|
if (lua_isnil(L, -1))
|
||||||
|
lua_pop(L, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
int t = lua_type(L, 2);
|
int t = lua_type(L, 2);
|
||||||
|
luaL_check_type(L, 1, LUA_TTABLE);
|
||||||
luaL_arg_check(L, t == LUA_TNIL || t == LUA_TTABLE, 2, "nil/table expected");
|
luaL_arg_check(L, t == LUA_TNIL || t == LUA_TTABLE, 2, "nil/table expected");
|
||||||
lua_settop(L, 2);
|
lua_settop(L, 2);
|
||||||
lua_setmetatable(L, 1);
|
lua_setmetatable(L, 1);
|
||||||
|
4
lua.h
4
lua.h
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
** $Id: lua.h,v 1.122 2002/03/07 18:15:10 roberto Exp roberto $
|
** $Id: lua.h,v 1.123 2002/03/18 18:18:35 roberto Exp roberto $
|
||||||
** Lua - An Extensible Extension Language
|
** Lua - An Extensible Extension Language
|
||||||
** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
|
** TeCGraf: Grupo de Tecnologia em Computacao Grafica, PUC-Rio, Brazil
|
||||||
** e-mail: info@lua.org
|
** e-mail: info@lua.org
|
||||||
@ -152,7 +152,7 @@ LUA_API void lua_gettable (lua_State *L, int index);
|
|||||||
LUA_API void lua_rawget (lua_State *L, int index);
|
LUA_API void lua_rawget (lua_State *L, int index);
|
||||||
LUA_API void lua_rawgeti (lua_State *L, int index, int n);
|
LUA_API void lua_rawgeti (lua_State *L, int index, int n);
|
||||||
LUA_API void lua_newtable (lua_State *L);
|
LUA_API void lua_newtable (lua_State *L);
|
||||||
LUA_API void lua_getmetatable (lua_State *L, int objindex);
|
LUA_API int lua_getmetatable (lua_State *L, int objindex);
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user