summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-24 15:04:51 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-24 15:04:51 +1000
commit39f0e15c8e834a439aaef35c50e76df0713433c4 (patch)
tree4db6342ff8e792cee77c48127705f988089c8158
parent8c0949281e8102d4e208869aac50267bd3fa25a9 (diff)
downloadfengari-39f0e15c8e834a439aaef35c50e76df0713433c4.tar.gz
fengari-39f0e15c8e834a439aaef35c50e76df0713433c4.tar.bz2
fengari-39f0e15c8e834a439aaef35c50e76df0713433c4.zip
src/lstate.js: Move preinit_thread into lua_State constructor
-rw-r--r--src/lstate.js43
1 files changed, 16 insertions, 27 deletions
diff --git a/src/lstate.js b/src/lstate.js
index 38c9b09..2413574 100644
--- a/src/lstate.js
+++ b/src/lstate.js
@@ -47,16 +47,25 @@ class lua_State {
constructor(g) {
this.id = g.id_counter++;
- this.base_ci = new CallInfo(); // Will be populated later
- this.top = 0;
- this.ci = null;
+ this.base_ci = new CallInfo(); /* CallInfo for first level (C calling Lua) */
+ this.top = NaN; /* first free slot in the stack */
+ this.stack_last = NaN; /* last free slot in the stack */
+ this.oldpc = NaN; /* last pc traced */
+
+ /* preinit_thread */
+ this.l_G = g;
this.stack = null;
- this.stack_last = NaN;
- this.openupval = null;
- this.status = TS.LUA_OK;
- this.next = null;
+ this.ci = null;
this.errorJmp = null;
+ this.nCcalls = 0;
+ this.hook = null;
+ this.hookmask = 0;
+ this.basehookcount = 0;
+ this.allowhook = 1;
+ this.hookcount = this.basehookcount;
+ this.openupval = null;
this.nny = 1;
+ this.status = TS.LUA_OK;
this.errfunc = 0;
}
@@ -135,29 +144,11 @@ const f_luaopen = function(L) {
g.version = lapi.lua_version(null);
};
-const preinit_thread = function(L, g) {
- L.l_G = g;
- L.stack = null;
- L.ci = null;
- L.errorJmp = null;
- L.nCcalls = 0;
- L.hook = null;
- L.hookmask = 0;
- L.basehookcount = 0;
- L.allowhook = 1;
- L.hookcount = L.basehookcount;
- L.openupval = null;
- L.nny = 1;
- L.status = TS.LUA_OK;
- L.errfunc = 0;
-};
-
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);
assert(L.top <= L.ci.top, "stack overflow");
- preinit_thread(L1, g);
L1.hookmask = L.hookmask;
L1.basehookcount = L.basehookcount;
L1.hook = L.hook;
@@ -174,8 +165,6 @@ const luaE_freethread = function(L, L1) {
const lua_newstate = function() {
let g = new global_State();
let L = new lua_State(g);
-
- preinit_thread(L, g);
g.mainthread = L;
if (ldo.luaD_rawrunprotected(L, f_luaopen, null) !== TS.LUA_OK) {