eris: refactoring table API so that table methods can see value being inserted

This commit is contained in:
2021-07-06 19:32:20 -04:00
parent a12133243c
commit 3bf8b1fadb
6 changed files with 40 additions and 56 deletions

View File

@@ -139,19 +139,13 @@ void luaV_settable (lua_State *L, const TValue *t, TValue *key, StkId val) {
const TValue *tm;
if (ttistable(t)) { /* `t' is a table? */
Table *h = hvalue(t);
TValue *oldval = cast(TValue *, luaH_get(h, key));
const TValue *oldval = luaH_get(h, key);
/* if previous value is not nil, there must be a previous entry
in the table; moreover, a metamethod has no relevance */
if (!ttisnil(oldval) ||
/* previous value is nil; must check the metamethod */
((tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL &&
/* no metamethod; is there a previous entry in the table? */
(oldval != luaO_nilobject ||
/* no previous entry; must create one. (The next test is
always true; we only need the assignment.) */
(oldval = luaH_newkey(L, h, key), 1)))) {
/* no metamethod and (now) there is an entry with given key */
setobj2t(L, oldval, val); /* assign new value to that entry */
((tm = fasttm(L, h->metatable, TM_NEWINDEX)) == NULL)) {
luaH_setupdate(L, h, key, val, oldval);
invalidateTMcache(h);
luaC_barrierback(L, obj2gco(h), val);
return;