From 4b764aa6a84289f04acde43108425c392d2e4806 Mon Sep 17 00:00:00 2001 From: Benoit Giannangeli Date: Wed, 22 Feb 2017 17:24:42 +0100 Subject: Tables are JS Maps, lua_next --- src/lobject.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'src/lobject.js') 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); } -- cgit v1.2.3-54-g00ecf