aboutsummaryrefslogtreecommitdiff
path: root/ltm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-04-04 11:23:41 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-04-04 11:23:41 -0300
commit03c6a05ec836c3a90a6b8d730120afdad39c092b (patch)
tree31f0bdf82969b1e082e92d7b5dd5d9e1496d64af /ltm.c
parent3d0b5edfe4df7ec54d6885b6b6ce917faddf6661 (diff)
downloadlua-03c6a05ec836c3a90a6b8d730120afdad39c092b.tar.gz
lua-03c6a05ec836c3a90a6b8d730120afdad39c092b.tar.bz2
lua-03c6a05ec836c3a90a6b8d730120afdad39c092b.zip
no more nil-in-table
Diffstat (limited to 'ltm.c')
-rw-r--r--ltm.c30
1 files changed, 1 insertions, 29 deletions
diff --git a/ltm.c b/ltm.c
index 2a9a4cbe..6d285510 100644
--- a/ltm.c
+++ b/ltm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ltm.c,v 2.65 2018/02/26 14:16:05 roberto Exp roberto $ 2** $Id: ltm.c,v 2.66 2018/02/27 17:48:28 roberto Exp roberto $
3** Tag methods 3** Tag methods
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -38,7 +38,6 @@ LUAI_DDEF const char *const luaT_typenames_[LUA_TOTALTAGS] = {
38void luaT_init (lua_State *L) { 38void luaT_init (lua_State *L) {
39 static const char *const luaT_eventname[] = { /* ORDER TM */ 39 static const char *const luaT_eventname[] = { /* ORDER TM */
40 "__index", "__newindex", 40 "__index", "__newindex",
41 "__undef", "__isdef",
42 "__gc", "__mode", "__len", "__eq", 41 "__gc", "__mode", "__len", "__eq",
43 "__add", "__sub", "__mul", "__mod", "__pow", 42 "__add", "__sub", "__mul", "__mod", "__pow",
44 "__div", "__idiv", 43 "__div", "__idiv",
@@ -250,30 +249,3 @@ void luaT_getvarargs (lua_State *L, CallInfo *ci, StkId where, int wanted) {
250 setnilvalue(s2v(where + i)); 249 setnilvalue(s2v(where + i));
251} 250}
252 251
253
254int luaT_keydef (lua_State *L, TValue *obj, TValue *key, int remove) {
255 const TValue *tm;
256 TMS event = remove ? TM_UNDEF : TM_ISDEF;
257 if (!ttistable(obj)) { /* not a table? */
258 tm = luaT_gettmbyobj(L, obj, event); /* get its metamethod */
259 if (notm(tm)) { /* no metamethod? */
260 const char *msg = remove ? "remove key from" : "check key from";
261 luaG_typeerror(L, obj, msg); /* error */
262 }
263 /* else will call metamethod 'tm' */
264 }
265 else { /* 'obj' is a table */
266 Table *t = hvalue(obj);
267 tm = fasttm(L, t->metatable, event);
268 if (tm == NULL) { /* no metamethod? */
269 const TValue *val = luaH_get(t, key); /* get entry */
270 int res = !isempty(val); /* true if entry is not empty */
271 if (remove && res) /* key is present and should be removed? */
272 setempty(cast(TValue*, val)); /* remove it */
273 return res;
274 }
275 /* else will call metamethod 'tm' */
276 }
277 luaT_callTMres(L, tm, obj, key, L->top);
278 return !l_isfalse(s2v(L->top));
279}