diff options
-rw-r--r-- | lapi.c | 13 | ||||
-rw-r--r-- | lauxlib.c | 9 | ||||
-rw-r--r-- | lbaselib.c | 14 | ||||
-rw-r--r-- | ldo.c | 4 | ||||
-rw-r--r-- | lgc.c | 7 | ||||
-rw-r--r-- | linit.c | 9 | ||||
-rw-r--r-- | loadlib.c | 9 | ||||
-rw-r--r-- | lstate.c | 14 | ||||
-rw-r--r-- | lstate.h | 4 | ||||
-rw-r--r-- | ltests.c | 8 | ||||
-rw-r--r-- | lua.c | 10 | ||||
-rw-r--r-- | lua.h | 15 |
12 files changed, 63 insertions, 53 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lapi.c,v 2.104 2009/12/15 11:25:36 roberto Exp roberto $ | 2 | ** $Id: lapi.c,v 2.105 2009/12/17 16:20:01 roberto Exp roberto $ |
3 | ** Lua API | 3 | ** Lua API |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -41,7 +41,7 @@ const char lua_ident[] = | |||
41 | 41 | ||
42 | static Table *getcurrenv (lua_State *L) { | 42 | static Table *getcurrenv (lua_State *L) { |
43 | if (L->ci->previous == NULL) /* no enclosing function? */ | 43 | if (L->ci->previous == NULL) /* no enclosing function? */ |
44 | return hvalue(&G(L)->l_gt); /* use global table as environment */ | 44 | return G(L)->l_gt; /* use global table as environment */ |
45 | else { | 45 | else { |
46 | Closure *func = curr_func(L); | 46 | Closure *func = curr_func(L); |
47 | return func->c.env; | 47 | return func->c.env; |
@@ -67,10 +67,9 @@ static TValue *index2addr (lua_State *L, int idx) { | |||
67 | sethvalue(L, &L->env, getcurrenv(L)); | 67 | sethvalue(L, &L->env, getcurrenv(L)); |
68 | return &L->env; | 68 | return &L->env; |
69 | } | 69 | } |
70 | case LUA_GLOBALSINDEX: return &G(L)->l_gt; | ||
71 | default: { | 70 | default: { |
72 | Closure *func = curr_func(L); | 71 | Closure *func = curr_func(L); |
73 | idx = LUA_GLOBALSINDEX - idx; | 72 | idx = LUA_ENVIRONINDEX - idx; |
74 | api_check(L, idx <= UCHAR_MAX + 1, "upvalue index too large"); | 73 | api_check(L, idx <= UCHAR_MAX + 1, "upvalue index too large"); |
75 | return (idx <= func->c.nupvalues) | 74 | return (idx <= func->c.nupvalues) |
76 | ? &func->c.upvalue[idx-1] | 75 | ? &func->c.upvalue[idx-1] |
@@ -204,11 +203,11 @@ static void moveto (lua_State *L, TValue *fr, int idx) { | |||
204 | } | 203 | } |
205 | else { | 204 | else { |
206 | setobj(L, to, fr); | 205 | setobj(L, to, fr); |
207 | if (idx < LUA_GLOBALSINDEX) /* function upvalue? */ | 206 | if (idx < LUA_ENVIRONINDEX) /* function upvalue? */ |
208 | luaC_barrier(L, curr_func(L), fr); | 207 | luaC_barrier(L, curr_func(L), fr); |
209 | } | 208 | } |
210 | /* LUA_GLOBALSINDEX and LUA_REGISTRYINDEX do not need gc barrier | 209 | /* LUA_REGISTRYINDEX does not need gc barrier |
211 | (collector revisits them before finishing collection) */ | 210 | (collector revisits it before finishing collection) */ |
212 | } | 211 | } |
213 | 212 | ||
214 | 213 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lauxlib.c,v 1.194 2009/11/25 15:27:51 roberto Exp roberto $ | 2 | ** $Id: lauxlib.c,v 1.195 2009/12/17 16:20:01 roberto Exp roberto $ |
3 | ** Auxiliary functions for building Lua libraries | 3 | ** Auxiliary functions for building Lua libraries |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -73,7 +73,7 @@ static int findfield (lua_State *L, int objidx, int level) { | |||
73 | static int pushglobalfuncname (lua_State *L, lua_Debug *ar) { | 73 | static int pushglobalfuncname (lua_State *L, lua_Debug *ar) { |
74 | int top = lua_gettop(L); | 74 | int top = lua_gettop(L); |
75 | lua_getinfo(L, "f", ar); /* push function */ | 75 | lua_getinfo(L, "f", ar); /* push function */ |
76 | lua_pushvalue(L, LUA_GLOBALSINDEX); /* push global table */ | 76 | lua_pushglobaltable(L); |
77 | if (findfield(L, top + 1, 2)) { | 77 | if (findfield(L, top + 1, 2)) { |
78 | lua_copy(L, -1, top + 1); /* move name to proper place */ | 78 | lua_copy(L, -1, top + 1); /* move name to proper place */ |
79 | lua_pop(L, 2); /* remove pushed values */ | 79 | lua_pop(L, 2); /* remove pushed values */ |
@@ -678,7 +678,8 @@ LUALIB_API void luaL_register (lua_State *L, const char *libname, | |||
678 | if (!lua_istable(L, -1)) { /* not found? */ | 678 | if (!lua_istable(L, -1)) { /* not found? */ |
679 | lua_pop(L, 1); /* remove previous result */ | 679 | lua_pop(L, 1); /* remove previous result */ |
680 | /* try global variable (and create one if it does not exist) */ | 680 | /* try global variable (and create one if it does not exist) */ |
681 | if (luaL_findtable(L, LUA_GLOBALSINDEX, libname, libsize(l)) != NULL) | 681 | lua_pushglobaltable(L); |
682 | if (luaL_findtable(L, 0, libname, libsize(l)) != NULL) | ||
682 | luaL_error(L, "name conflict for module " LUA_QS, libname); | 683 | luaL_error(L, "name conflict for module " LUA_QS, libname); |
683 | lua_pushvalue(L, -1); | 684 | lua_pushvalue(L, -1); |
684 | lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */ | 685 | lua_setfield(L, -3, libname); /* _LOADED[libname] = new table */ |
@@ -713,7 +714,7 @@ LUALIB_API const char *luaL_gsub (lua_State *L, const char *s, const char *p, | |||
713 | LUALIB_API const char *luaL_findtable (lua_State *L, int idx, | 714 | LUALIB_API const char *luaL_findtable (lua_State *L, int idx, |
714 | const char *fname, int szhint) { | 715 | const char *fname, int szhint) { |
715 | const char *e; | 716 | const char *e; |
716 | lua_pushvalue(L, idx); | 717 | if (idx) lua_pushvalue(L, idx); |
717 | do { | 718 | do { |
718 | e = strchr(fname, '.'); | 719 | e = strchr(fname, '.'); |
719 | if (e == NULL) e = fname + strlen(fname); | 720 | if (e == NULL) e = fname + strlen(fname); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lbaselib.c,v 1.232 2009/12/15 11:25:16 roberto Exp roberto $ | 2 | ** $Id: lbaselib.c,v 1.233 2009/12/17 16:20:01 roberto Exp roberto $ |
3 | ** Basic library | 3 | ** Basic library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -23,7 +23,7 @@ | |||
23 | static int luaB_print (lua_State *L) { | 23 | static int luaB_print (lua_State *L) { |
24 | int n = lua_gettop(L); /* number of arguments */ | 24 | int n = lua_gettop(L); /* number of arguments */ |
25 | int i; | 25 | int i; |
26 | lua_getfield(L, LUA_GLOBALSINDEX, "tostring"); | 26 | lua_getfield(L, LUA_ENVIRONINDEX, "tostring"); |
27 | for (i=1; i<=n; i++) { | 27 | for (i=1; i<=n; i++) { |
28 | const char *s; | 28 | const char *s; |
29 | size_t l; | 29 | size_t l; |
@@ -125,7 +125,7 @@ static void getfunc (lua_State *L, int opt) { | |||
125 | static int luaB_getfenv (lua_State *L) { | 125 | static int luaB_getfenv (lua_State *L) { |
126 | getfunc(L, 1); | 126 | getfunc(L, 1); |
127 | if (lua_iscfunction(L, -1)) /* is a C function? */ | 127 | if (lua_iscfunction(L, -1)) /* is a C function? */ |
128 | lua_pushvalue(L, LUA_GLOBALSINDEX); /* return the global env. */ | 128 | lua_pushglobaltable(L); /* return the global env. */ |
129 | else | 129 | else |
130 | lua_getfenv(L, -1); | 130 | lua_getfenv(L, -1); |
131 | return 1; | 131 | return 1; |
@@ -695,12 +695,12 @@ static void auxopen (lua_State *L, const char *name, | |||
695 | 695 | ||
696 | static void base_open (lua_State *L) { | 696 | static void base_open (lua_State *L) { |
697 | /* set global _G */ | 697 | /* set global _G */ |
698 | lua_pushvalue(L, LUA_GLOBALSINDEX); | 698 | lua_pushglobaltable(L); |
699 | lua_setfield(L, LUA_GLOBALSINDEX, "_G"); | 699 | lua_setfield(L, LUA_ENVIRONINDEX, "_G"); |
700 | /* open lib into global table */ | 700 | /* open lib into global table */ |
701 | luaL_register(L, "_G", base_funcs); | 701 | luaL_register(L, "_G", base_funcs); |
702 | lua_pushliteral(L, LUA_VERSION); | 702 | lua_pushliteral(L, LUA_VERSION); |
703 | lua_setfield(L, LUA_GLOBALSINDEX, "_VERSION"); /* set global _VERSION */ | 703 | lua_setfield(L, LUA_ENVIRONINDEX, "_VERSION"); /* set global _VERSION */ |
704 | /* `ipairs' and `pairs' need auxiliary functions as upvalues */ | 704 | /* `ipairs' and `pairs' need auxiliary functions as upvalues */ |
705 | auxopen(L, "ipairs", luaB_ipairs, ipairsaux); | 705 | auxopen(L, "ipairs", luaB_ipairs, ipairsaux); |
706 | auxopen(L, "pairs", luaB_pairs, luaB_next); | 706 | auxopen(L, "pairs", luaB_pairs, luaB_next); |
@@ -711,7 +711,7 @@ static void base_open (lua_State *L) { | |||
711 | lua_pushliteral(L, "kv"); | 711 | lua_pushliteral(L, "kv"); |
712 | lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */ | 712 | lua_setfield(L, -2, "__mode"); /* metatable(w).__mode = "kv" */ |
713 | lua_pushcclosure(L, luaB_newproxy, 1); | 713 | lua_pushcclosure(L, luaB_newproxy, 1); |
714 | lua_setfield(L, LUA_GLOBALSINDEX, "newproxy"); /* set global `newproxy' */ | 714 | lua_setfield(L, LUA_ENVIRONINDEX, "newproxy"); /* set global `newproxy' */ |
715 | } | 715 | } |
716 | 716 | ||
717 | 717 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ldo.c,v 2.77 2009/12/17 12:26:09 roberto Exp roberto $ | 2 | ** $Id: ldo.c,v 2.78 2009/12/17 12:28:57 roberto Exp roberto $ |
3 | ** Stack and Call structure of Lua | 3 | ** Stack and Call structure of Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -619,7 +619,7 @@ static void f_parser (lua_State *L, void *ud) { | |||
619 | : luaY_parser(L, p->z, &p->buff, &p->varl, p->name); | 619 | : luaY_parser(L, p->z, &p->buff, &p->varl, p->name); |
620 | setptvalue2s(L, L->top, tf); | 620 | setptvalue2s(L, L->top, tf); |
621 | incr_top(L); | 621 | incr_top(L); |
622 | cl = luaF_newLclosure(L, tf->sizeupvalues, hvalue(&G(L)->l_gt)); | 622 | cl = luaF_newLclosure(L, tf->sizeupvalues, G(L)->l_gt); |
623 | cl->l.p = tf; | 623 | cl->l.p = tf; |
624 | setclvalue(L, L->top - 1, cl); | 624 | setclvalue(L, L->top - 1, cl); |
625 | for (i = 0; i < tf->sizeupvalues; i++) /* initialize upvalues */ | 625 | for (i = 0; i < tf->sizeupvalues; i++) /* initialize upvalues */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lgc.c,v 2.65 2009/12/11 21:31:14 roberto Exp roberto $ | 2 | ** $Id: lgc.c,v 2.66 2009/12/16 16:42:58 roberto Exp roberto $ |
3 | ** Garbage Collector | 3 | ** Garbage Collector |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -230,7 +230,7 @@ static void markroot (lua_State *L) { | |||
230 | g->weak = g->ephemeron = g->allweak = NULL; | 230 | g->weak = g->ephemeron = g->allweak = NULL; |
231 | markobject(g, g->mainthread); | 231 | markobject(g, g->mainthread); |
232 | /* make global table and registry to be traversed before main stack */ | 232 | /* make global table and registry to be traversed before main stack */ |
233 | markvalue(g, &g->l_gt); | 233 | markobject(g, g->l_gt); |
234 | markvalue(g, &g->l_registry); | 234 | markvalue(g, &g->l_registry); |
235 | markmt(g); | 235 | markmt(g); |
236 | markbeingfnz(g); /* mark any finalizing object left from previous cycle */ | 236 | markbeingfnz(g); /* mark any finalizing object left from previous cycle */ |
@@ -703,8 +703,7 @@ static void atomic (lua_State *L) { | |||
703 | g->gcstate = GCSatomic; | 703 | g->gcstate = GCSatomic; |
704 | lua_assert(!iswhite(obj2gco(g->mainthread))); | 704 | lua_assert(!iswhite(obj2gco(g->mainthread))); |
705 | markobject(g, L); /* mark running thread */ | 705 | markobject(g, L); /* mark running thread */ |
706 | /* global table, registry, and global metatables may be changed by API */ | 706 | /* registry and global metatables may be changed by API */ |
707 | markvalue(g, &g->l_gt); | ||
708 | markvalue(g, &g->l_registry); | 707 | markvalue(g, &g->l_registry); |
709 | markmt(g); /* mark basic metatables */ | 708 | markmt(g); /* mark basic metatables */ |
710 | /* remark occasional upvalues of (maybe) dead threads */ | 709 | /* remark occasional upvalues of (maybe) dead threads */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: linit.c,v 1.21 2009/12/11 13:40:44 roberto Exp roberto $ | 2 | ** $Id: linit.c,v 1.22 2009/12/17 12:26:09 roberto Exp roberto $ |
3 | ** Initialization of libraries for lua.c and other clients | 3 | ** Initialization of libraries for lua.c and other clients |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -57,16 +57,19 @@ LUALIB_API void luaL_openlibs (lua_State *L) { | |||
57 | lua_call(L, 1, 0); | 57 | lua_call(L, 1, 0); |
58 | } | 58 | } |
59 | /* add open functions from 'preloadedlibs' into 'package.preload' table */ | 59 | /* add open functions from 'preloadedlibs' into 'package.preload' table */ |
60 | luaL_findtable(L, LUA_GLOBALSINDEX, "package.preload", 0); | 60 | lua_pushglobaltable(L); |
61 | luaL_findtable(L, 0, "package.preload", 0); | ||
61 | for (lib = preloadedlibs; lib->func; lib++) { | 62 | for (lib = preloadedlibs; lib->func; lib++) { |
62 | lua_pushcfunction(L, lib->func); | 63 | lua_pushcfunction(L, lib->func); |
63 | lua_setfield(L, -2, lib->name); | 64 | lua_setfield(L, -2, lib->name); |
64 | } | 65 | } |
65 | lua_pop(L, 1); /* remove package.preload table */ | 66 | lua_pop(L, 1); /* remove package.preload table */ |
66 | #if defined(LUA_COMPAT_DEBUGLIB) | 67 | #if defined(LUA_COMPAT_DEBUGLIB) |
67 | lua_getfield(L, LUA_GLOBALSINDEX, "require"); | 68 | lua_pushglobaltable(L); |
69 | lua_getfield(L, -1, "require"); | ||
68 | lua_pushliteral(L, LUA_DBLIBNAME); | 70 | lua_pushliteral(L, LUA_DBLIBNAME); |
69 | lua_call(L, 1, 0); /* call 'require"debug"' */ | 71 | lua_call(L, 1, 0); /* call 'require"debug"' */ |
72 | lua_pop(L, 1); /* remove global table */ | ||
70 | #endif | 73 | #endif |
71 | } | 74 | } |
72 | 75 | ||
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: loadlib.c,v 1.69 2009/12/17 12:26:09 roberto Exp roberto $ | 2 | ** $Id: loadlib.c,v 1.70 2009/12/17 13:06:47 roberto Exp roberto $ |
3 | ** Dynamic library loader for Lua | 3 | ** Dynamic library loader for Lua |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | ** | 5 | ** |
@@ -608,7 +608,8 @@ static int ll_module (lua_State *L) { | |||
608 | if (!lua_istable(L, -1)) { /* not found? */ | 608 | if (!lua_istable(L, -1)) { /* not found? */ |
609 | lua_pop(L, 1); /* remove previous result */ | 609 | lua_pop(L, 1); /* remove previous result */ |
610 | /* try global variable (and create one if it does not exist) */ | 610 | /* try global variable (and create one if it does not exist) */ |
611 | if (luaL_findtable(L, LUA_GLOBALSINDEX, modname, 1) != NULL) | 611 | lua_pushglobaltable(L); |
612 | if (luaL_findtable(L, 0, modname, 1) != NULL) | ||
612 | return luaL_error(L, "name conflict for module " LUA_QS, modname); | 613 | return luaL_error(L, "name conflict for module " LUA_QS, modname); |
613 | lua_pushvalue(L, -1); | 614 | lua_pushvalue(L, -1); |
614 | lua_setfield(L, loaded, modname); /* _LOADED[modname] = new table */ | 615 | lua_setfield(L, loaded, modname); /* _LOADED[modname] = new table */ |
@@ -635,7 +636,7 @@ static int ll_seeall (lua_State *L) { | |||
635 | lua_pushvalue(L, -1); | 636 | lua_pushvalue(L, -1); |
636 | lua_setmetatable(L, 1); | 637 | lua_setmetatable(L, 1); |
637 | } | 638 | } |
638 | lua_pushvalue(L, LUA_GLOBALSINDEX); | 639 | lua_pushglobaltable(L); |
639 | lua_setfield(L, -2, "__index"); /* mt.__index = _G */ | 640 | lua_setfield(L, -2, "__index"); /* mt.__index = _G */ |
640 | return 0; | 641 | return 0; |
641 | } | 642 | } |
@@ -713,7 +714,7 @@ LUAMOD_API int luaopen_package (lua_State *L) { | |||
713 | /* set field `preload' */ | 714 | /* set field `preload' */ |
714 | lua_newtable(L); | 715 | lua_newtable(L); |
715 | lua_setfield(L, -2, "preload"); | 716 | lua_setfield(L, -2, "preload"); |
716 | lua_pushvalue(L, LUA_GLOBALSINDEX); | 717 | lua_pushglobaltable(L); |
717 | luaL_register(L, NULL, ll_funcs); /* open lib into global table */ | 718 | luaL_register(L, NULL, ll_funcs); /* open lib into global table */ |
718 | lua_pop(L, 1); | 719 | lua_pop(L, 1); |
719 | return 1; /* return 'package' table */ | 720 | return 1; /* return 'package' table */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.c,v 2.66 2009/12/16 16:42:58 roberto Exp roberto $ | 2 | ** $Id: lstate.c,v 2.67 2009/12/17 12:26:09 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 | */ |
@@ -119,7 +119,8 @@ static int cpcall (lua_State *L) { | |||
119 | lua_CFunction f = *(lua_CFunction *)lua_touserdata(L, 1); | 119 | lua_CFunction f = *(lua_CFunction *)lua_touserdata(L, 1); |
120 | lua_remove(L, 1); /* remove f from stack */ | 120 | lua_remove(L, 1); /* remove f from stack */ |
121 | /* restore original environment for 'cpcall' */ | 121 | /* restore original environment for 'cpcall' */ |
122 | lua_copy(L, LUA_GLOBALSINDEX, LUA_ENVIRONINDEX); | 122 | lua_pushglobaltable(L); |
123 | lua_replace(L, LUA_ENVIRONINDEX); | ||
123 | return f(L); | 124 | return f(L); |
124 | } | 125 | } |
125 | 126 | ||
@@ -138,10 +139,13 @@ static void init_registry (lua_State *L, global_State *g) { | |||
138 | setthvalue(L, &mt, L); | 139 | setthvalue(L, &mt, L); |
139 | setobj2t(L, luaH_setint(L, registry, LUA_RIDX_MAINTHREAD), &mt); | 140 | setobj2t(L, luaH_setint(L, registry, LUA_RIDX_MAINTHREAD), &mt); |
140 | /* registry[LUA_RIDX_CPCALL] = cpcall */ | 141 | /* registry[LUA_RIDX_CPCALL] = cpcall */ |
141 | cp = luaF_newCclosure(L, 0, hvalue(&g->l_gt)); | 142 | cp = luaF_newCclosure(L, 0, g->l_gt); |
142 | cp->c.f = cpcall; | 143 | cp->c.f = cpcall; |
143 | setclvalue(L, &mt, cp); | 144 | setclvalue(L, &mt, cp); |
144 | setobj2t(L, luaH_setint(L, registry, LUA_RIDX_CPCALL), &mt); | 145 | setobj2t(L, luaH_setint(L, registry, LUA_RIDX_CPCALL), &mt); |
146 | /* registry[LUA_RIDX_GLOBALS] = l_gt */ | ||
147 | sethvalue(L, &mt, g->l_gt); | ||
148 | setobj2t(L, luaH_setint(L, registry, LUA_RIDX_GLOBALS), &mt); | ||
145 | } | 149 | } |
146 | 150 | ||
147 | 151 | ||
@@ -152,7 +156,7 @@ static void f_luaopen (lua_State *L, void *ud) { | |||
152 | global_State *g = G(L); | 156 | global_State *g = G(L); |
153 | UNUSED(ud); | 157 | UNUSED(ud); |
154 | stack_init(L, L); /* init stack */ | 158 | stack_init(L, L); /* init stack */ |
155 | sethvalue(L, &g->l_gt, luaH_new(L)); /* table of globals */ | 159 | g->l_gt = luaH_new(L); /* table of globals */ |
156 | init_registry(L, g); | 160 | init_registry(L, g); |
157 | luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ | 161 | luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ |
158 | luaT_init(L); | 162 | luaT_init(L); |
@@ -253,7 +257,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud) { | |||
253 | g->strt.nuse = 0; | 257 | g->strt.nuse = 0; |
254 | g->strt.hash = NULL; | 258 | g->strt.hash = NULL; |
255 | setnilvalue(&g->l_registry); | 259 | setnilvalue(&g->l_registry); |
256 | setnilvalue(&g->l_gt); | 260 | g->l_gt = NULL; |
257 | luaZ_initbuffer(L, &g->buff); | 261 | luaZ_initbuffer(L, &g->buff); |
258 | g->panic = NULL; | 262 | g->panic = NULL; |
259 | g->version = lua_version(NULL); | 263 | g->version = lua_version(NULL); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lstate.h,v 2.50 2009/11/26 11:39:20 roberto Exp roberto $ | 2 | ** $Id: lstate.h,v 2.51 2009/12/11 13:39:34 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 | */ |
@@ -138,7 +138,7 @@ typedef struct global_State { | |||
138 | int gcstepmul; /* GC `granularity' */ | 138 | int gcstepmul; /* GC `granularity' */ |
139 | lua_CFunction panic; /* to be called in unprotected errors */ | 139 | lua_CFunction panic; /* to be called in unprotected errors */ |
140 | TValue l_registry; | 140 | TValue l_registry; |
141 | TValue l_gt; /* table of globals */ | 141 | struct Table *l_gt; /* table of globals */ |
142 | struct lua_State *mainthread; | 142 | struct lua_State *mainthread; |
143 | UpVal uvhead; /* head of double-linked list of all open upvalues */ | 143 | UpVal uvhead; /* head of double-linked list of all open upvalues */ |
144 | const lua_Number *version; /* pointer to version number */ | 144 | const lua_Number *version; /* pointer to version number */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: ltests.c,v 2.84 2009/12/16 16:42:58 roberto Exp roberto $ | 2 | ** $Id: ltests.c,v 2.85 2009/12/17 16:20:01 roberto Exp roberto $ |
3 | ** Internal Module for Debugging of the Lua Implementation | 3 | ** Internal Module for Debugging of the Lua Implementation |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -376,7 +376,7 @@ int lua_checkmemory (lua_State *L) { | |||
376 | GCObject *o; | 376 | GCObject *o; |
377 | UpVal *uv; | 377 | UpVal *uv; |
378 | checkliveness(g, &g->l_registry); | 378 | checkliveness(g, &g->l_registry); |
379 | checkliveness(g, &g->l_gt); | 379 | lua_assert(!isdead(g, obj2gco(g->l_gt))); |
380 | checkstack(g, g->mainthread); | 380 | checkstack(g, g->mainthread); |
381 | for (o = g->rootgc; o != obj2gco(g->mainthread); o = gch(o)->next) { | 381 | for (o = g->rootgc; o != obj2gco(g->mainthread); o = gch(o)->next) { |
382 | lua_assert(!testbits(o->gch.marked, bit2mask(SEPARATED, SFIXEDBIT))); | 382 | lua_assert(!testbits(o->gch.marked, bit2mask(SEPARATED, SFIXEDBIT))); |
@@ -767,7 +767,7 @@ static int loadlib (lua_State *L) { | |||
767 | {NULL, NULL} | 767 | {NULL, NULL} |
768 | }; | 768 | }; |
769 | lua_State *L1 = getstate(L); | 769 | lua_State *L1 = getstate(L); |
770 | lua_pushvalue(L1, LUA_GLOBALSINDEX); | 770 | lua_pushglobaltable(L1); |
771 | luaL_register(L1, NULL, libs); | 771 | luaL_register(L1, NULL, libs); |
772 | return 0; | 772 | return 0; |
773 | } | 773 | } |
@@ -878,7 +878,7 @@ static int getindex_aux (lua_State *L, lua_State *L1, const char **pc) { | |||
878 | skip(pc); | 878 | skip(pc); |
879 | switch (*(*pc)++) { | 879 | switch (*(*pc)++) { |
880 | case 'R': return LUA_REGISTRYINDEX; | 880 | case 'R': return LUA_REGISTRYINDEX; |
881 | case 'G': return LUA_GLOBALSINDEX; | 881 | case 'G': return luaL_error(L, "deprecated index 'G'"); |
882 | case 'E': return LUA_ENVIRONINDEX; | 882 | case 'E': return LUA_ENVIRONINDEX; |
883 | case 'U': return lua_upvalueindex(getnum_aux(L, L1, pc)); | 883 | case 'U': return lua_upvalueindex(getnum_aux(L, L1, pc)); |
884 | default: (*pc)--; return getnum_aux(L, L1, pc); | 884 | default: (*pc)--; return getnum_aux(L, L1, pc); |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.c,v 1.179 2009/12/17 13:07:41 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.180 2009/12/17 16:20:01 roberto Exp roberto $ |
3 | ** Lua stand-alone interpreter | 3 | ** Lua stand-alone interpreter |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -214,7 +214,7 @@ static int dostring (lua_State *L, const char *s, const char *name) { | |||
214 | 214 | ||
215 | 215 | ||
216 | static int dolibrary (lua_State *L, const char *name) { | 216 | static int dolibrary (lua_State *L, const char *name) { |
217 | lua_getfield(L, LUA_GLOBALSINDEX, "require"); | 217 | lua_getfield(L, LUA_ENVIRONINDEX, "require"); |
218 | lua_pushstring(L, name); | 218 | lua_pushstring(L, name); |
219 | return report(L, docall(L, 1, 1)); | 219 | return report(L, docall(L, 1, 1)); |
220 | } | 220 | } |
@@ -222,7 +222,7 @@ static int dolibrary (lua_State *L, const char *name) { | |||
222 | 222 | ||
223 | static const char *get_prompt (lua_State *L, int firstline) { | 223 | static const char *get_prompt (lua_State *L, int firstline) { |
224 | const char *p; | 224 | const char *p; |
225 | lua_getfield(L, LUA_GLOBALSINDEX, firstline ? "_PROMPT" : "_PROMPT2"); | 225 | lua_getfield(L, LUA_ENVIRONINDEX, firstline ? "_PROMPT" : "_PROMPT2"); |
226 | p = lua_tostring(L, -1); | 226 | p = lua_tostring(L, -1); |
227 | if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2); | 227 | if (p == NULL) p = (firstline ? LUA_PROMPT : LUA_PROMPT2); |
228 | lua_pop(L, 1); /* remove global */ | 228 | lua_pop(L, 1); /* remove global */ |
@@ -296,7 +296,7 @@ static void dotty (lua_State *L) { | |||
296 | report(L, status); | 296 | report(L, status); |
297 | if (status == LUA_OK && lua_gettop(L) > 0) { /* any result to print? */ | 297 | if (status == LUA_OK && lua_gettop(L) > 0) { /* any result to print? */ |
298 | luaL_checkstack(L, LUA_MINSTACK, "too many results to print"); | 298 | luaL_checkstack(L, LUA_MINSTACK, "too many results to print"); |
299 | lua_getfield(L, LUA_GLOBALSINDEX, "print"); | 299 | lua_getfield(L, LUA_ENVIRONINDEX, "print"); |
300 | lua_insert(L, 1); | 300 | lua_insert(L, 1); |
301 | if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != LUA_OK) | 301 | if (lua_pcall(L, lua_gettop(L)-1, 0, 0) != LUA_OK) |
302 | l_message(progname, lua_pushfstring(L, | 302 | l_message(progname, lua_pushfstring(L, |
@@ -315,7 +315,7 @@ static int handle_script (lua_State *L, char **argv, int n) { | |||
315 | int status; | 315 | int status; |
316 | const char *fname; | 316 | const char *fname; |
317 | int narg = getargs(L, argv, n); /* collect arguments */ | 317 | int narg = getargs(L, argv, n); /* collect arguments */ |
318 | lua_setfield(L, LUA_GLOBALSINDEX, "arg"); | 318 | lua_setfield(L, LUA_ENVIRONINDEX, "arg"); |
319 | fname = argv[n]; | 319 | fname = argv[n]; |
320 | if (strcmp(fname, "-") == 0 && strcmp(argv[n-1], "--") != 0) | 320 | if (strcmp(fname, "-") == 0 && strcmp(argv[n-1], "--") != 0) |
321 | fname = NULL; /* stdin */ | 321 | fname = NULL; /* stdin */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.h,v 1.254 2009/12/17 16:20:01 roberto Exp roberto $ | 2 | ** $Id: lua.h,v 1.255 2009/12/18 15:32:36 roberto Exp roberto $ |
3 | ** Lua - A Scripting Language | 3 | ** Lua - A Scripting Language |
4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) | 4 | ** Lua.org, PUC-Rio, Brazil (http://www.lua.org) |
5 | ** See Copyright Notice at the end of this file | 5 | ** See Copyright Notice at the end of this file |
@@ -35,8 +35,7 @@ | |||
35 | */ | 35 | */ |
36 | #define LUA_REGISTRYINDEX LUAI_FIRSTPSEUDOIDX | 36 | #define LUA_REGISTRYINDEX LUAI_FIRSTPSEUDOIDX |
37 | #define LUA_ENVIRONINDEX (LUA_REGISTRYINDEX - 1) | 37 | #define LUA_ENVIRONINDEX (LUA_REGISTRYINDEX - 1) |
38 | #define LUA_GLOBALSINDEX (LUA_ENVIRONINDEX - 1) | 38 | #define lua_upvalueindex(i) (LUA_ENVIRONINDEX - (i)) |
39 | #define lua_upvalueindex(i) (LUA_GLOBALSINDEX-(i)) | ||
40 | 39 | ||
41 | 40 | ||
42 | /* thread status */ | 41 | /* thread status */ |
@@ -92,7 +91,8 @@ typedef void * (*lua_Alloc) (void *ud, void *ptr, size_t osize, size_t nsize); | |||
92 | /* predefined values in the registry */ | 91 | /* predefined values in the registry */ |
93 | #define LUA_RIDX_MAINTHREAD 1 | 92 | #define LUA_RIDX_MAINTHREAD 1 |
94 | #define LUA_RIDX_CPCALL 2 | 93 | #define LUA_RIDX_CPCALL 2 |
95 | #define LUA_RIDX_LAST LUA_RIDX_CPCALL | 94 | #define LUA_RIDX_GLOBALS 3 |
95 | #define LUA_RIDX_LAST LUA_RIDX_GLOBALS | ||
96 | 96 | ||
97 | 97 | ||
98 | /* type of numbers in Lua */ | 98 | /* type of numbers in Lua */ |
@@ -315,8 +315,8 @@ LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud); | |||
315 | #define lua_pushliteral(L, s) \ | 315 | #define lua_pushliteral(L, s) \ |
316 | lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1) | 316 | lua_pushlstring(L, "" s, (sizeof(s)/sizeof(char))-1) |
317 | 317 | ||
318 | #define lua_setglobal(L,s) lua_setfield(L, LUA_GLOBALSINDEX, (s)) | 318 | #define lua_pushglobaltable(L) \ |
319 | #define lua_getglobal(L,s) lua_getfield(L, LUA_GLOBALSINDEX, (s)) | 319 | lua_rawgeti(L, LUA_REGISTRYINDEX, LUA_RIDX_GLOBALS) |
320 | 320 | ||
321 | #define lua_tostring(L,i) lua_tolstring(L, (i), NULL) | 321 | #define lua_tostring(L,i) lua_tolstring(L, (i), NULL) |
322 | 322 | ||
@@ -343,6 +343,9 @@ LUA_API void (lua_setallocf) (lua_State *L, lua_Alloc f, void *ud); | |||
343 | #define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ) | 343 | #define lua_equal(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPEQ) |
344 | #define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT) | 344 | #define lua_lessthan(L,idx1,idx2) lua_compare(L,(idx1),(idx2),LUA_OPLT) |
345 | 345 | ||
346 | #define lua_setglobal(L,s) lua_setfield(L, LUA_ENVIRONINDEX, (s)) | ||
347 | #define lua_getglobal(L,s) lua_getfield(L, LUA_ENVIRONINDEX, (s)) | ||
348 | |||
346 | #endif | 349 | #endif |
347 | 350 | ||
348 | 351 | ||