diff options
author | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-02-22 17:24:42 +0100 |
---|---|---|
committer | Benoit Giannangeli <benoit.giannangeli@boursorama.fr> | 2017-02-22 17:24:42 +0100 |
commit | 4b764aa6a84289f04acde43108425c392d2e4806 (patch) | |
tree | eac70ef0e59290a1af12eabed20489c7529a8636 /src/lobject.js | |
parent | 9ff3e69b37f7b7603056b684a19b1dd8c641c8d5 (diff) | |
download | fengari-4b764aa6a84289f04acde43108425c392d2e4806.tar.gz fengari-4b764aa6a84289f04acde43108425c392d2e4806.tar.bz2 fengari-4b764aa6a84289f04acde43108425c392d2e4806.zip |
Tables are JS Maps, lua_next
Diffstat (limited to 'src/lobject.js')
-rw-r--r-- | src/lobject.js | 13 |
1 files changed, 4 insertions, 9 deletions
diff --git a/src/lobject.js b/src/lobject.js index 0a0b615..2ba45ad 100644 --- a/src/lobject.js +++ b/src/lobject.js @@ -113,10 +113,7 @@ const nil = new TValue(CT.LUA_TNIL, null); class Table extends TValue { constructor(array, hash) { - super(CT.LUA_TTABLE, { - array: array !== undefined ? array : [], - hash: new Map(hash) - }); + super(CT.LUA_TTABLE, new Map(hash)); this.metatable = null; } @@ -124,11 +121,9 @@ class Table extends TValue { static keyValue(key) { // Those lua values are used by value, others by reference if (key instanceof TValue - && [CT.LUA_TNUMBER, - CT.LUA_TSTRING, + && [CT.LUA_TSTRING, CT.LUA_TSHRSTR, CT.LUA_TLNGSTR, - CT.LUA_TNUMFLT, CT.LUA_TNUMINT].indexOf(key.type) > -1) { key = key.value; } @@ -140,7 +135,7 @@ class Table extends TValue { key = Table.keyValue(key); if (typeof key === 'number' && key > 0) { - table.value.array[key - 1] = value; // Lua array starts at 1 + table.value.hash.set(key - 1, value); // Lua array starts at 1 } else { table.value.hash.set(key, value); } @@ -151,7 +146,7 @@ class Table extends TValue { let v = nil; if (typeof key === 'number' && key > 0) { - v = table.value.array[key - 1]; // Lua array starts at 1 + v = table.value.hash.get(key - 1); // Lua array starts at 1 } else { v = table.value.hash.get(key); } |