From b45dc3dd1e3f9ef4548a5e422cb6f7daa9a3ba79 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Thu, 27 Apr 2017 12:15:10 +1000 Subject: Add table construction function --- src/ltable.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src/ltable.js') diff --git a/src/ltable.js b/src/ltable.js index 7972f08..432a91d 100644 --- a/src/ltable.js +++ b/src/ltable.js @@ -4,7 +4,6 @@ const defs = require('./defs.js'); const lobject = require('./lobject.js'); const CT = defs.constant_types; -const TValue = lobject.TValue; const ordered_intindexes = function(table) { @@ -24,6 +23,11 @@ const ordered_indexes = function(table) { }); }; +const luaH_new = function(L) { + let t = new Map(); + return t; +}; + /* ** Try to find a boundary in table 't'. A 'boundary' is an integer index ** such that t[i] is non-nil and t[i+1] is nil (and 0 if t[1] is nil). @@ -62,9 +66,9 @@ const luaH_next = function(L, table, keyI) { let tnidx = typeof nidx; if (tnidx === 'number' && nidx % 1 === 0) - L.stack[keyI] = new TValue(CT.LUA_TNUMINT, indexes[i + 1]); + L.stack[keyI] = new lobject.TValue(CT.LUA_TNUMINT, indexes[i + 1]); else if (tnidx === 'string') - L.stack[keyI] = new TValue(CT.LUA_TLNGSTR, indexes[i + 1].split('|').map(e => Number.parseInt(e)).slice(0, -1)); + L.stack[keyI] = new lobject.TValue(CT.LUA_TLNGSTR, indexes[i + 1].split('|').map(e => Number.parseInt(e)).slice(0, -1)); else L.stack[keyI] = indexes[i + 1]; @@ -75,5 +79,6 @@ const luaH_next = function(L, table, keyI) { return 0; }; +module.exports.luaH_new = luaH_new; module.exports.luaH_next = luaH_next; module.exports.luaH_getn = luaH_getn; -- cgit v1.2.3-54-g00ecf