diff options
Diffstat (limited to 'src/lstate.js')
-rw-r--r-- | src/lstate.js | 47 |
1 files changed, 25 insertions, 22 deletions
diff --git a/src/lstate.js b/src/lstate.js index db046dc..6e623b9 100644 --- a/src/lstate.js +++ b/src/lstate.js @@ -1,21 +1,28 @@ "use strict"; -const assert = require('assert'); - -const defs = require('./defs.js'); +const { + LUA_MINSTACK, + LUA_RIDX_GLOBALS, + LUA_RIDX_MAINTHREAD, + constant_types: { + LUA_NUMTAGS, + LUA_TNIL, + LUA_TTABLE, + LUA_TTHREAD + }, + thread_status: { + LUA_OK + } +} = require('./defs.js'); const lobject = require('./lobject.js'); const ldo = require('./ldo.js'); const lapi = require('./lapi.js'); const ltable = require('./ltable.js'); -const lfunc = require('./lfunc.js'); const ltm = require('./ltm.js'); -const CT = defs.constant_types; -const TS = defs.thread_status; -const LUA_NUMTAGS = CT.LUA_NUMTAGS; const EXTRA_STACK = 5; -const BASIC_STACK_SIZE = 2 * defs.LUA_MINSTACK; +const BASIC_STACK_SIZE = 2 * LUA_MINSTACK; class CallInfo { @@ -62,9 +69,8 @@ class lua_State { this.basehookcount = 0; this.allowhook = 1; this.hookcount = this.basehookcount; - this.openupval = null; this.nny = 1; - this.status = TS.LUA_OK; + this.status = LUA_OK; this.errfunc = 0; } @@ -73,11 +79,11 @@ class lua_State { class global_State { constructor() { - this.id_counter = 0; /* used to give objects unique ids */ + this.id_counter = 1; /* used to give objects unique ids */ this.ids = new WeakMap(); this.mainthread = null; - this.l_registry = new lobject.TValue(CT.LUA_TNIL, null); + this.l_registry = new lobject.TValue(LUA_TNIL, null); this.panic = null; this.atnativeerror = null; this.version = null; @@ -111,8 +117,8 @@ const stack_init = function(L1, L) { ci.callstatus = 0; ci.funcOff = L1.top; ci.func = L1.stack[L1.top]; - L1.stack[L1.top++] = new lobject.TValue(CT.LUA_TNIL, null); - ci.top = L1.top + defs.LUA_MINSTACK; + L1.stack[L1.top++] = new lobject.TValue(LUA_TNIL, null); + ci.top = L1.top + LUA_MINSTACK; L1.ci = ci; }; @@ -128,8 +134,8 @@ const freestack = function(L) { const init_registry = function(L, g) { let registry = ltable.luaH_new(L); g.l_registry.sethvalue(registry); - ltable.luaH_setint(registry, defs.LUA_RIDX_MAINTHREAD, new lobject.TValue(CT.LUA_TTHREAD, L)); - ltable.luaH_setint(registry, defs.LUA_RIDX_GLOBALS, new lobject.TValue(CT.LUA_TTABLE, ltable.luaH_new(L))); + ltable.luaH_setint(registry, LUA_RIDX_MAINTHREAD, new lobject.TValue(LUA_TTHREAD, L)); + ltable.luaH_setint(registry, LUA_RIDX_GLOBALS, new lobject.TValue(LUA_TTABLE, ltable.luaH_new(L))); }; /* @@ -147,9 +153,8 @@ const f_luaopen = function(L) { const lua_newthread = function(L) { let g = L.l_G; let L1 = new lua_State(g); - L.stack[L.top] = new lobject.TValue(CT.LUA_TTHREAD, L1); - L.top++; - assert(L.top <= L.ci.top, "stack overflow"); + L.stack[L.top] = new lobject.TValue(LUA_TTHREAD, L1); + lapi.api_incr_top(L); L1.hookmask = L.hookmask; L1.basehookcount = L.basehookcount; L1.hook = L.hook; @@ -159,7 +164,6 @@ const lua_newthread = function(L) { }; const luaE_freethread = function(L, L1) { - lfunc.luaF_close(L1, L1.stack); freestack(L1); }; @@ -168,7 +172,7 @@ const lua_newstate = function() { let L = new lua_State(g); g.mainthread = L; - if (ldo.luaD_rawrunprotected(L, f_luaopen, null) !== TS.LUA_OK) { + if (ldo.luaD_rawrunprotected(L, f_luaopen, null) !== LUA_OK) { L = null; } @@ -176,7 +180,6 @@ const lua_newstate = function() { }; const close_state = function(L) { - lfunc.luaF_close(L, L.stack); /* close all upvalues for this thread */ freestack(L); }; |