diff options
Diffstat (limited to 'src/lapi.js')
-rw-r--r-- | src/lapi.js | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/src/lapi.js b/src/lapi.js index 72c35f0..99b0859 100644 --- a/src/lapi.js +++ b/src/lapi.js @@ -14,6 +14,7 @@ const lua = require('./lua.js'); const luaconf = require('./luaconf.js'); const lundump = require('./lundump.js'); const lvm = require('./lvm.js'); +const ltable = require('./ltable.js'); const MAXUPVAL = lfunc.MAXUPVAL; const CT = lua.constant_types; const TS = lua.thread_status; @@ -335,8 +336,8 @@ const auxsetstr = function(L, t, k) { assert(1 < L.top - L.ci.funcOff, "not enough elements in the stack"); - if (t.ttistable() && !t.__index(t, k).ttisnil()) { - t.__newindex(t, k, L.stack[L.top - 1]); + if (t.ttistable() && !lobject.table_index(t, k).ttisnil()) { + lobject.table_newindex(t, k, L.stack[L.top - 1]); L.top--; /* pop value */ } else { L.stack[L.top++] = str; @@ -399,7 +400,7 @@ const lua_rawset = function(L, idx) { assert(2 < L.top - L.ci.funcOff, "not enough elements in the stack"); let o = index2addr(L, idx); assert(o.ttistable(), "table expected"); - o.__newindex(o, L.stack[L.top - 2], L.stack[L.top - 1]); + lobject.table_newindex(o, L.stack[L.top - 2], L.stack[L.top - 1]); L.top -= 2; }; @@ -408,7 +409,7 @@ const lua_rawsetp = function(L, idx, p) { let o = index2addr(L, idx); assert(L, o.ttistable(), "table expected"); let k = p; - o.__newindex(o, k, L.stack[L.top - 1]); + lobject.table_newindex(o, k, L.stack[L.top - 1]); L.top--; }; @@ -420,7 +421,7 @@ const auxgetstr = function(L, t, k) { assert(Array.isArray(k), "key must be an array of bytes"); let str = L.l_G.intern(k); - let slot = t.__index(t, k); + let slot = lobject.table_index(t, k); if (t.ttistable() && !slot.ttisnil()) { L.stack[L.top++] = slot; assert(L.top <= L.ci.top, "stack overflow"); @@ -438,7 +439,7 @@ const lua_rawgeti = function(L, idx, n) { assert(t.ttistable(), "table expected"); - L.stack[L.top++] = t.__index(t, n); + L.stack[L.top++] = lobject.table_index(t, n); assert(L.top <= L.ci.top, "stack overflow"); @@ -449,7 +450,7 @@ const lua_rawgetp = function(L, idx, p) { let t = index2addr(L, idx); assert(t.ttistable(), "table expected"); let k = p; - L.stack[L.top++] = t.__index(t, k); + L.stack[L.top++] = lobject.table_index(t, k); assert(L.top <= L.ci.top, "stack overflow"); return L.stack[L.top - 1].ttnov(); }; @@ -459,14 +460,14 @@ const lua_rawget = function(L, idx) { assert(t.ttistable(t), "table expected"); - L.stack[L.top - 1] = t.__index(t, L.stack[L.top - 1]); + L.stack[L.top - 1] = lobject.table_index(t, L.stack[L.top - 1]); return L.stack[L.top - 1].ttnov(); }; // narray and nrec are mostly useless for this implementation const lua_createtable = function(L, narray, nrec) { - let t = new lobject.Table(); + let t = new lobject.TValue(CT.LUA_TTABLE, new Map()); L.stack[L.top++] = t; assert(L.top <= L.ci.top, "stack overflow"); @@ -509,8 +510,8 @@ const lua_getupvalue = function(L, funcindex, n) { let name = up.name; let val = up.val; if (name) - L.stack[L.top++] = new TValue(name.type, name.value); - return name; + L.stack[L.top++] = new TValue(val.type, val.value); + return name.value; }; const lua_setupvalue = function(L, funcindex, n) { @@ -525,7 +526,7 @@ const lua_setupvalue = function(L, funcindex, n) { val.type = L.stack[L.top].type; val.value = L.stack[L.top].value; } - return name; + return name.value; }; const lua_newtable = function(L) { @@ -576,7 +577,7 @@ const lua_getfield = function(L, idx, k) { const lua_geti = function(L, idx, n) { let t = index2addr(L, idx); - let slot = t.__index(t, n); + let slot = lobject.table_index(t, n); if (!slot.ttisnil()) { L.stack[L.top++] = slot; assert(L.top <= L.ci.top, "stack overflow"); @@ -645,7 +646,7 @@ const lua_rawlen = function(L, idx) { case CT.LUA_TUSERDATA: return o.len; case CT.LUA_TTABLE: - return o.luaH_getn(); + return ltable.luaH_getn(o); default: return 0; } @@ -807,7 +808,7 @@ const lua_load = function(L, reader, data, chunckname, mode) { let reg = L.l_G.l_registry; let gt = reg.value.get(lua.LUA_RIDX_GLOBALS); /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */ - f.upvals[0].u.value = gt; + f.upvals[0].u.value = new TValue(gt.type, gt.value); } } return status; @@ -923,7 +924,7 @@ const lua_error = function(L) { const lua_next = function(L, idx) { let t = index2addr(L, idx); assert(t.ttistable(), "table expected"); - let more = t.luaH_next(L, L.top - 1); + let more = ltable.luaH_next(L, t, L.top - 1); if (more) { L.top++; assert(L.top <= L.ci.top, "stack overflow"); |