summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lapi.js2
-rw-r--r--src/ldebug.js3
-rw-r--r--src/lobject.js3
-rw-r--r--src/lparser.js3
-rw-r--r--src/lstate.js5
-rw-r--r--src/ltable.js11
-rw-r--r--src/lvm.js2
7 files changed, 19 insertions, 10 deletions
diff --git a/src/lapi.js b/src/lapi.js
index 184630c..4b5223a 100644
--- a/src/lapi.js
+++ b/src/lapi.js
@@ -460,7 +460,7 @@ const lua_rawget = function(L, idx) {
// narray and nrec are mostly useless for this implementation
const lua_createtable = function(L, narray, nrec) {
- let t = new lobject.TValue(CT.LUA_TTABLE, new Map());
+ let t = new lobject.TValue(CT.LUA_TTABLE, ltable.luaH_new(L));
L.stack[L.top++] = t;
assert(L.top <= L.ci.top, "stack overflow");
diff --git a/src/ldebug.js b/src/ldebug.js
index 984f441..6350c3e 100644
--- a/src/ldebug.js
+++ b/src/ldebug.js
@@ -7,6 +7,7 @@ const defs = require('./defs.js');
const ldo = require('./ldo.js');
const lobject = require('./lobject.js');
const lstate = require('./lstate.js');
+const ltable = require('./ltable.js');
const luaconf = require('./luaconf.js');
const OC = require('./lopcodes.js');
const lvm = require('./lvm.js');
@@ -179,7 +180,7 @@ const collectvalidlines = function(L, f) {
assert(L.top <= L.ci.top, "stack overflow");
} else {
let lineinfo = f.l.p.lineinfo;
- let t = new TValue(CT.LUA_TTABLE, new Map());
+ let t = new TValue(CT.LUA_TTABLE, ltable.luaH_new(L));
L.stack[L.top++] = t;
assert(L.top <= L.ci.top, "stack overflow");
let v = new TValue(true, CT.LUA_TBOOLEAN);
diff --git a/src/lobject.js b/src/lobject.js
index e785e68..00f5ac6 100644
--- a/src/lobject.js
+++ b/src/lobject.js
@@ -7,6 +7,7 @@ const defs = require('./defs.js');
const ljstype = require('./ljstype.js');
const luaconf = require('./luaconf.js');
const llimit = require('./llimit.js');
+const ltable = require('./ltable.js');
const CT = defs.constant_types;
const UpVal = require('./lfunc.js').UpVal;
const char = defs.char;
@@ -172,7 +173,7 @@ class LClosure extends TValue {
_ENV.v = null;
_ENV.u.open.next = null;
_ENV.u.open.touched = true;
- _ENV.u.value = new TValue(CT.LUA_TTABLE, new Map());
+ _ENV.u.value = new TValue(CT.LUA_TTABLE, ltable.luaH_new(L));
this.upvals = [
_ENV
diff --git a/src/lparser.js b/src/lparser.js
index 41a0b22..86b286a 100644
--- a/src/lparser.js
+++ b/src/lparser.js
@@ -9,6 +9,7 @@ const llex = require('./llex.js');
const llimit = require('./llimit.js');
const lobject = require('./lobject.js');
const lopcode = require('./lopcodes.js');
+const ltable = require('./ltable.js');
const BinOpr = lcode.BinOpr;
const OpCodesI = lopcode.OpCodesI;
const Proto = lfunc.Proto;
@@ -1546,7 +1547,7 @@ const luaY_parser = function(L, z, buff, dyd, name, firstchar) {
let funcstate = new FuncState();
let cl = lfunc.luaF_newLclosure(L, 1); /* create main closure */
L.stack[L.top++] = cl;
- lexstate.h = new TValue(defs.CT.LUA_TTABLE, new Map()); /* create table for scanner */
+ lexstate.h = new TValue(defs.CT.LUA_TTABLE, ltable.luaH_new(L)); /* create table for scanner */
L.stack[L.top++] = lexstate.h;
funcstate.f = cl.p = new Proto(L);
funcstate.f.source = new TValue(defs.CT.LUA_TLNGSTR, name);
diff --git a/src/lstate.js b/src/lstate.js
index 23374c0..1a4cbd5 100644
--- a/src/lstate.js
+++ b/src/lstate.js
@@ -7,6 +7,7 @@ const defs = require('./defs.js');
const lobject = require('./lobject.js');
const ldo = require('./ldo.js');
const lapi = require('./lapi.js');
+const ltable = require('./ltable.js');
const luaT_init = require('./ltm.js').luaT_init;
const CT = defs.constant_types;
const TS = defs.thread_status;
@@ -106,10 +107,10 @@ const stack_init = function(L1, L) {
** Create registry table and its predefined values
*/
const init_registry = function(L, g) {
- let registry = new lobject.TValue(CT.LUA_TTABLE, new Map());
+ let registry = new lobject.TValue(CT.LUA_TTABLE, ltable.luaH_new(L));
g.l_registry = registry;
registry.value.set(defs.LUA_RIDX_MAINTHREAD, L);
- registry.value.set(defs.LUA_RIDX_GLOBALS, new lobject.TValue(CT.LUA_TTABLE, new Map()));
+ registry.value.set(defs.LUA_RIDX_GLOBALS, new lobject.TValue(CT.LUA_TTABLE, ltable.luaH_new(L)));
};
/*
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;
diff --git a/src/lvm.js b/src/lvm.js
index 7af81b7..7f4392f 100644
--- a/src/lvm.js
+++ b/src/lvm.js
@@ -207,7 +207,7 @@ const luaV_execute = function(L) {
break;
}
case OCi.OP_NEWTABLE: {
- L.stack[ra] = new TValue(CT.LUA_TTABLE, new Map());
+ L.stack[ra] = new TValue(CT.LUA_TTABLE, ltable.luaH_new(L));
break;
}
case OCi.OP_SELF: {