diff options
author | daurnimator <quae@daurnimator.com> | 2017-05-23 14:54:41 +1000 |
---|---|---|
committer | daurnimator <quae@daurnimator.com> | 2017-05-23 15:06:36 +1000 |
commit | beb5d0abd707c112953719a8ac077dff88a5ecf7 (patch) | |
tree | a8be2dfdf82a0b5a02da52cb08175c2b1f3698b9 /src/ltable.js | |
parent | fe6129f7edaa3a9dee990cd90f765e7196d992b6 (diff) | |
download | fengari-beb5d0abd707c112953719a8ac077dff88a5ecf7.tar.gz fengari-beb5d0abd707c112953719a8ac077dff88a5ecf7.tar.bz2 fengari-beb5d0abd707c112953719a8ac077dff88a5ecf7.zip |
src/ltable.js: Convert float keys that fit in an integer to integers
Diffstat (limited to 'src/ltable.js')
-rw-r--r-- | src/ltable.js | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/ltable.js b/src/ltable.js index 88b09e3..b408cd1 100644 --- a/src/ltable.js +++ b/src/ltable.js @@ -29,8 +29,8 @@ const table_hash = function(L, key) { if (isNaN(key.value)) return ldebug.luaG_runerror(L, defs.to_luastring("table index is NaN", true)); /* fall through */ + case CT.LUA_TNUMINT: /* takes advantage of floats and integers being same in JS */ case CT.LUA_TBOOLEAN: - case CT.LUA_TNUMINT: case CT.LUA_TTABLE: case CT.LUA_TLCL: case CT.LUA_TLCF: @@ -167,6 +167,13 @@ const setgeneric = function(t, hash, key) { if (v) return v.value; + let kv = key.value; + if ((key.ttisfloat() && (kv|0) === kv)) { /* does index fit in an integer? */ + /* insert it as an integer */ + key = new lobject.TValue(CT.LUA_TNUMINT, kv); + } else { + key = new lobject.TValue(key.type, kv); + } let tv = new lobject.TValue(CT.LUA_TNIL, null); add(t, hash, key, tv); return tv; @@ -193,7 +200,7 @@ const luaH_setint = function(t, key, value) { const luaH_set = function(L, t, key) { assert(key instanceof lobject.TValue); let hash = table_hash(L, key); - return setgeneric(t, hash, new lobject.TValue(key.type, key.value)); + return setgeneric(t, hash, key); }; const luaH_delete = function(L, t, key) { |