aboutsummaryrefslogtreecommitdiff
path: root/lstate.c
diff options
context:
space:
mode:
Diffstat (limited to 'lstate.c')
-rw-r--r--lstate.c19
1 files changed, 9 insertions, 10 deletions
diff --git a/lstate.c b/lstate.c
index b571c828..cb52eac3 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 2.61 2009/09/30 20:49:47 roberto Exp roberto $ 2** $Id: lstate.c,v 2.62 2009/10/05 16:44:33 roberto Exp roberto $
3** Global State 3** Global State
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -108,18 +108,18 @@ static int cpcall (lua_State *L) {
108/* 108/*
109** Create registry table and its predefined values 109** Create registry table and its predefined values
110*/ 110*/
111static void init_registry (lua_State *L) { 111static void init_registry (lua_State *L, global_State *g) {
112 Closure *cp; 112 Closure *cp;
113 TValue mt; 113 TValue mt;
114 /* create registry */ 114 /* create registry */
115 Table *registry = luaH_new(L); 115 Table *registry = luaH_new(L);
116 sethvalue(L, registry(L), registry); 116 sethvalue(L, &g->l_registry, registry);
117 luaH_resize(L, registry, LUA_RIDX_LAST, 0); 117 luaH_resize(L, registry, LUA_RIDX_LAST, 0);
118 /* registry[LUA_RIDX_MAINTHREAD] = L */ 118 /* registry[LUA_RIDX_MAINTHREAD] = L */
119 setthvalue(L, &mt, L); 119 setthvalue(L, &mt, L);
120 setobj2t(L, luaH_setint(L, registry, LUA_RIDX_MAINTHREAD), &mt); 120 setobj2t(L, luaH_setint(L, registry, LUA_RIDX_MAINTHREAD), &mt);
121 /* registry[LUA_RIDX_CPCALL] = cpcall */ 121 /* registry[LUA_RIDX_CPCALL] = cpcall */
122 cp = luaF_newCclosure(L, 0, hvalue(gt(L))); 122 cp = luaF_newCclosure(L, 0, hvalue(&g->l_gt));
123 cp->c.f = cpcall; 123 cp->c.f = cpcall;
124 setclvalue(L, &mt, cp); 124 setclvalue(L, &mt, cp);
125 setobj2t(L, luaH_setint(L, registry, LUA_RIDX_CPCALL), &mt); 125 setobj2t(L, luaH_setint(L, registry, LUA_RIDX_CPCALL), &mt);
@@ -127,14 +127,14 @@ static void init_registry (lua_State *L) {
127 127
128 128
129/* 129/*
130** open parts of a state that may cause memory-allocation errors 130** open parts of the state that may cause memory-allocation errors
131*/ 131*/
132static void f_luaopen (lua_State *L, void *ud) { 132static void f_luaopen (lua_State *L, void *ud) {
133 global_State *g = G(L); 133 global_State *g = G(L);
134 UNUSED(ud); 134 UNUSED(ud);
135 stack_init(L, L); /* init stack */ 135 stack_init(L, L); /* init stack */
136 sethvalue(L, gt(L), luaH_new(L)); /* table of globals */ 136 sethvalue(L, &g->l_gt, luaH_new(L)); /* table of globals */
137 init_registry(L); 137 init_registry(L, g);
138 luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ 138 luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */
139 luaT_init(L); 139 luaT_init(L);
140 luaX_init(L); 140 luaX_init(L);
@@ -164,7 +164,6 @@ static void preinit_state (lua_State *L, global_State *g) {
164 L->base_ci.next = L->base_ci.previous = NULL; 164 L->base_ci.next = L->base_ci.previous = NULL;
165 L->ci = &L->base_ci; 165 L->ci = &L->base_ci;
166 L->errfunc = 0; 166 L->errfunc = 0;
167 setnilvalue(gt(L));
168} 167}
169 168
170 169
@@ -190,7 +189,6 @@ LUA_API lua_State *lua_newthread (lua_State *L) {
190 api_incr_top(L); 189 api_incr_top(L);
191 preinit_state(L1, G(L)); 190 preinit_state(L1, G(L));
192 stack_init(L1, L); /* init stack */ 191 stack_init(L1, L); /* init stack */
193 setobj2n(L, gt(L1), gt(L)); /* share table of globals */
194 L1->hookmask = L->hookmask; 192 L1->hookmask = L->hookmask;
195 L1->basehookcount = L->basehookcount; 193 L1->basehookcount = L->basehookcount;
196 L1->hook = L->hook; 194 L1->hook = L->hook;
@@ -236,7 +234,8 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) {
236 g->strt.size = 0; 234 g->strt.size = 0;
237 g->strt.nuse = 0; 235 g->strt.nuse = 0;
238 g->strt.hash = NULL; 236 g->strt.hash = NULL;
239 setnilvalue(registry(L)); 237 setnilvalue(&g->l_registry);
238 setnilvalue(&g->l_gt);
240 luaZ_initbuffer(L, &g->buff); 239 luaZ_initbuffer(L, &g->buff);
241 g->panic = NULL; 240 g->panic = NULL;
242 g->version = lua_version(NULL); 241 g->version = lua_version(NULL);