From fb1de39c6b9a5812e229aa8ad4f87e594f8ea179 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Thu, 11 May 2017 15:08:06 +1000 Subject: src/lapi.js: Use luaH_delete when rawset-ing nil --- src/lapi.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/lapi.js b/src/lapi.js index 307d4e3..e033f69 100644 --- a/src/lapi.js +++ b/src/lapi.js @@ -404,8 +404,14 @@ const lua_rawset = function(L, idx) { assert(2 < L.top - L.ci.funcOff, "not enough elements in the stack"); let o = index2addr(L, idx); assert(o.ttistable(), "table expected"); - let slot = ltable.luaH_set(o.value, L.stack[L.top - 2]); - slot.setfrom(L.stack[L.top - 1]); + let k = L.stack[L.top - 2]; + let v = L.stack[L.top - 1]; + if (v.ttisnil()) { + ltable.luaH_delete(o.value, k); + } else { + let slot = ltable.luaH_set(o.value, k); + slot.setfrom(v); + } L.top -= 2; }; @@ -422,8 +428,13 @@ const lua_rawsetp = function(L, idx, p) { let o = index2addr(L, idx); assert(L, o.ttistable(), "table expected"); let k = new TValue(CT.LUA_TLIGHTUSERDATA, p); - let slot = ltable.luaH_set(o.value, k); - slot.setfrom(L.stack[L.top - 1]); + let v = L.stack[L.top - 1]; + if (v.ttisnil()) { + ltable.luaH_delete(o.value, k); + } else { + let slot = ltable.luaH_set(o.value, k); + slot.setfrom(v); + } L.top--; }; -- cgit v1.2.3-70-g09d2