diff options
author | daurnimator <quae@daurnimator.com> | 2017-05-11 15:08:06 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-05-11 15:19:35 +1000 |
commit | fb1de39c6b9a5812e229aa8ad4f87e594f8ea179 (patch) | |
tree | 1f342196b1c0e0555d6dc951d3616d9502cfb553 /src/lapi.js | |
parent | d7bdbc932ac22df593ba013118c0835c5638d084 (diff) | |
download | fengari-fb1de39c6b9a5812e229aa8ad4f87e594f8ea179.tar.gz fengari-fb1de39c6b9a5812e229aa8ad4f87e594f8ea179.tar.bz2 fengari-fb1de39c6b9a5812e229aa8ad4f87e594f8ea179.zip |
src/lapi.js: Use luaH_delete when rawset-ing nil
Diffstat (limited to 'src/lapi.js')
-rw-r--r-- | src/lapi.js | 19 |
1 files 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--; }; |