aboutsummaryrefslogtreecommitdiff
path: root/lvm.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-02-23 10:16:18 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2018-02-23 10:16:18 -0300
commit9243c414d92c253edd908f438caa31e2aa16f3f4 (patch)
treee8959a48f4672037aef061cc6eb82bba21d0766b /lvm.c
parent477ca2fe8ceaf79038972977915987adbef0e425 (diff)
downloadlua-9243c414d92c253edd908f438caa31e2aa16f3f4.tar.gz
lua-9243c414d92c253edd908f438caa31e2aa16f3f4.tar.bz2
lua-9243c414d92c253edd908f438caa31e2aa16f3f4.zip
first version of empty entries in tables
(so that, in the future, tables can contain regular nil entries)
Diffstat (limited to 'lvm.c')
-rw-r--r--lvm.c21
1 files changed, 11 insertions, 10 deletions
diff --git a/lvm.c b/lvm.c
index efde6fb2..99e0d6b7 100644
--- a/lvm.c
+++ b/lvm.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lvm.c,v 2.345 2018/02/21 15:49:32 roberto Exp roberto $ 2** $Id: lvm.c,v 2.346 2018/02/21 19:43:44 roberto Exp roberto $
3** Lua virtual machine 3** Lua virtual machine
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -168,7 +168,7 @@ static int forlimit (const TValue *obj, lua_Integer *p, lua_Integer step,
168/* 168/*
169** Finish the table access 'val = t[key]'. 169** Finish the table access 'val = t[key]'.
170** if 'slot' is NULL, 't' is not a table; otherwise, 'slot' points to 170** if 'slot' is NULL, 't' is not a table; otherwise, 'slot' points to
171** t[k] entry (which must be nil). 171** t[k] entry (which must be empty).
172*/ 172*/
173void luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val, 173void luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val,
174 const TValue *slot) { 174 const TValue *slot) {
@@ -178,12 +178,12 @@ void luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val,
178 if (slot == NULL) { /* 't' is not a table? */ 178 if (slot == NULL) { /* 't' is not a table? */
179 lua_assert(!ttistable(t)); 179 lua_assert(!ttistable(t));
180 tm = luaT_gettmbyobj(L, t, TM_INDEX); 180 tm = luaT_gettmbyobj(L, t, TM_INDEX);
181 if (ttisnil(tm)) 181 if (notm(tm))
182 luaG_typeerror(L, t, "index"); /* no metamethod */ 182 luaG_typeerror(L, t, "index"); /* no metamethod */
183 /* else will try the metamethod */ 183 /* else will try the metamethod */
184 } 184 }
185 else { /* 't' is a table */ 185 else { /* 't' is a table */
186 lua_assert(ttisnil(slot)); 186 lua_assert(isempty(slot));
187 tm = fasttm(L, hvalue(t)->metatable, TM_INDEX); /* table's metamethod */ 187 tm = fasttm(L, hvalue(t)->metatable, TM_INDEX); /* table's metamethod */
188 if (tm == NULL) { /* no metamethod? */ 188 if (tm == NULL) { /* no metamethod? */
189 setnilvalue(s2v(val)); /* result is nil */ 189 setnilvalue(s2v(val)); /* result is nil */
@@ -209,8 +209,8 @@ void luaV_finishget (lua_State *L, const TValue *t, TValue *key, StkId val,
209/* 209/*
210** Finish a table assignment 't[key] = val'. 210** Finish a table assignment 't[key] = val'.
211** If 'slot' is NULL, 't' is not a table. Otherwise, 'slot' points 211** If 'slot' is NULL, 't' is not a table. Otherwise, 'slot' points
212** to the entry 't[key]', or to 'luaO_nilobject' if there is no such 212** to the entry 't[key]', or to 'luaH_emptyobject' if there is no such
213** entry. (The value at 'slot' must be nil, otherwise 'luaV_fastget' 213** entry. (The value at 'slot' must be empty, otherwise 'luaV_fastget'
214** would have done the job.) 214** would have done the job.)
215*/ 215*/
216void luaV_finishset (lua_State *L, const TValue *t, TValue *key, 216void luaV_finishset (lua_State *L, const TValue *t, TValue *key,
@@ -220,10 +220,10 @@ void luaV_finishset (lua_State *L, const TValue *t, TValue *key,
220 const TValue *tm; /* '__newindex' metamethod */ 220 const TValue *tm; /* '__newindex' metamethod */
221 if (slot != NULL) { /* is 't' a table? */ 221 if (slot != NULL) { /* is 't' a table? */
222 Table *h = hvalue(t); /* save 't' table */ 222 Table *h = hvalue(t); /* save 't' table */
223 lua_assert(ttisnil(slot)); /* old value must be nil */ 223 lua_assert(isempty(slot)); /* slot must be empty */
224 tm = fasttm(L, h->metatable, TM_NEWINDEX); /* get metamethod */ 224 tm = fasttm(L, h->metatable, TM_NEWINDEX); /* get metamethod */
225 if (tm == NULL) { /* no metamethod? */ 225 if (tm == NULL) { /* no metamethod? */
226 if (slot == luaO_nilobject) /* no previous entry? */ 226 if (slot == luaH_emptyobject) /* no previous entry? */
227 slot = luaH_newkey(L, h, key); /* create one */ 227 slot = luaH_newkey(L, h, key); /* create one */
228 /* no metamethod and (now) there is an entry with given key */ 228 /* no metamethod and (now) there is an entry with given key */
229 setobj2t(L, cast(TValue *, slot), val); /* set its new value */ 229 setobj2t(L, cast(TValue *, slot), val); /* set its new value */
@@ -234,7 +234,8 @@ void luaV_finishset (lua_State *L, const TValue *t, TValue *key,
234 /* else will try the metamethod */ 234 /* else will try the metamethod */
235 } 235 }
236 else { /* not a table; check metamethod */ 236 else { /* not a table; check metamethod */
237 if (ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX))) 237 tm = luaT_gettmbyobj(L, t, TM_NEWINDEX);
238 if (notm(tm))
238 luaG_typeerror(L, t, "index"); 239 luaG_typeerror(L, t, "index");
239 } 240 }
240 /* try the metamethod */ 241 /* try the metamethod */
@@ -586,7 +587,7 @@ void luaV_objlen (lua_State *L, StkId ra, const TValue *rb) {
586 } 587 }
587 default: { /* try metamethod */ 588 default: { /* try metamethod */
588 tm = luaT_gettmbyobj(L, rb, TM_LEN); 589 tm = luaT_gettmbyobj(L, rb, TM_LEN);
589 if (ttisnil(tm)) /* no metamethod? */ 590 if (notm(tm)) /* no metamethod? */
590 luaG_typeerror(L, rb, "get length of"); 591 luaG_typeerror(L, rb, "get length of");
591 break; 592 break;
592 } 593 }