summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lvm.js10
-rw-r--r--tests/ltablib.js2
2 files changed, 9 insertions, 3 deletions
diff --git a/src/lvm.js b/src/lvm.js
index 0d30484..4484bf2 100644
--- a/src/lvm.js
+++ b/src/lvm.js
@@ -1079,7 +1079,10 @@ const settable = function(L, table, key, v, recur) {
let element = ltable.luaH_set(table.value, key);
if (!element.ttisnil()) {
- element.setfrom(v);
+ if (v.ttisnil())
+ ltable.luaH_delete(table.value, key);
+ else
+ element.setfrom(v);
} else {
luaV_finishset(L, table, key, v, element, recur);
}
@@ -1094,7 +1097,10 @@ const luaV_finishset = function(L, t, key, val, slot, recur) {
assert(slot.ttisnil());
tm = ltm.luaT_gettmbyobj(L, t, ltm.TMS.TM_NEWINDEX); // TODO: fasttm
if (tm.ttisnil()) {
- slot.setfrom(val);
+ if (val.ttisnil())
+ ltable.luaH_delete(t.value, key);
+ else
+ slot.setfrom(val);
return;
}
} else { /* not a table; check metamethod */
diff --git a/tests/ltablib.js b/tests/ltablib.js
index 8789f9e..e209db3 100644
--- a/tests/ltablib.js
+++ b/tests/ltablib.js
@@ -184,7 +184,7 @@ test('table.remove', function (t) {
[...lua.lua_topointer(L, -1).strong.entries()]
.filter(e => typeof e[0] === 'number')
.map(e => e[1].value.value).sort(),
- [1, 2, 3, 4, null, null],
+ [1, 2, 3, 4],
"Correct element(s) on the stack"
);
});