diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-10-23 17:12:19 -0200 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2009-10-23 17:12:19 -0200 |
| commit | 5bc91c640588ca77b9f84146fc88fcc9bdbfbcd1 (patch) | |
| tree | d5d049ad2357648cabe25c19a8620566e9f27131 /lstate.c | |
| parent | f5073de0a72562e1998f23052715e56a3b9fde18 (diff) | |
| download | lua-5bc91c640588ca77b9f84146fc88fcc9bdbfbcd1.tar.gz lua-5bc91c640588ca77b9f84146fc88fcc9bdbfbcd1.tar.bz2 lua-5bc91c640588ca77b9f84146fc88fcc9bdbfbcd1.zip | |
no more one environment per thread: all threads share a single global
environment
Diffstat (limited to 'lstate.c')
| -rw-r--r-- | lstate.c | 19 |
1 files changed, 9 insertions, 10 deletions
| @@ -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 | */ |
| 111 | static void init_registry (lua_State *L) { | 111 | static 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 | */ |
| 132 | static void f_luaopen (lua_State *L, void *ud) { | 132 | static 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); |
