summaryrefslogtreecommitdiff
path: root/src/lstate.js
diff options
context:
space:
mode:
authordaurnimator <quae@daurnimator.com>2017-05-24 14:55:51 +1000
committerdaurnimator <quae@daurnimator.com>2017-05-24 14:55:51 +1000
commit8c0949281e8102d4e208869aac50267bd3fa25a9 (patch)
treec74a4fefcd273dda8f1559697f98d3f7bfa44286 /src/lstate.js
parent1b48f9b50a2e4edefdffd5d33efab929296a395c (diff)
downloadfengari-8c0949281e8102d4e208869aac50267bd3fa25a9.tar.gz
fengari-8c0949281e8102d4e208869aac50267bd3fa25a9.tar.bz2
fengari-8c0949281e8102d4e208869aac50267bd3fa25a9.zip
src/lstate.js: Create lua_State given global_State (not vice-versa)
Diffstat (limited to 'src/lstate.js')
-rw-r--r--src/lstate.js17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/lstate.js b/src/lstate.js
index 124322d..38c9b09 100644
--- a/src/lstate.js
+++ b/src/lstate.js
@@ -44,8 +44,9 @@ class CallInfo {
class lua_State {
- constructor() {
- this.id = null;
+ constructor(g) {
+ this.id = g.id_counter++;
+
this.base_ci = new CallInfo(); // Will be populated later
this.top = 0;
this.ci = null;
@@ -63,10 +64,10 @@ class lua_State {
class global_State {
- constructor(L) {
+ constructor() {
this.id_counter = 0; /* used to give objects unique ids */
- this.mainthread = L;
+ this.mainthread = null;
this.l_registry = new lobject.TValue(CT.LUA_TNIL, null);
this.panic = null;
this.atnativeerror = null;
@@ -135,7 +136,6 @@ const f_luaopen = function(L) {
};
const preinit_thread = function(L, g) {
- L.id = g.id_counter++;
L.l_G = g;
L.stack = null;
L.ci = null;
@@ -154,7 +154,7 @@ const preinit_thread = function(L, g) {
const lua_newthread = function(L) {
let g = L.l_G;
- let L1 = new lua_State();
+ 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);
@@ -172,10 +172,11 @@ const luaE_freethread = function(L, L1) {
};
const lua_newstate = function() {
- let L = new lua_State();
- let g = new global_State(L);
+ 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) {
L = null;