aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-03-13 12:55:42 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-03-13 12:55:42 -0300
commit22ef84b6c8d980eb869f414610f8ff5f25568ca7 (patch)
tree150de147a765e98015bfd4e8cd67f8bf3f157ef3
parent63a2b62468d2aabb1086a8c88d32ff96c658c96b (diff)
downloadlua-22ef84b6c8d980eb869f414610f8ff5f25568ca7.tar.gz
lua-22ef84b6c8d980eb869f414610f8ff5f25568ca7.tar.bz2
lua-22ef84b6c8d980eb869f414610f8ff5f25568ca7.zip
'_ENV' name permanently stored in global state for easier access
-rw-r--r--ldebug.c4
-rw-r--r--llex.h3
-rw-r--r--lparser.c9
-rw-r--r--lstate.c4
-rw-r--r--lstate.h3
5 files changed, 11 insertions, 12 deletions
diff --git a/ldebug.c b/ldebug.c
index 898efe53..08560acd 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 2.65 2010/03/05 14:01:29 roberto Exp roberto $ 2** $Id: ldebug.c,v 2.66 2010/03/12 19:14:06 roberto Exp roberto $
3** Debug Interface 3** Debug Interface
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -304,7 +304,7 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int reg,
304 ? luaF_getlocalname(p, t + 1, pc) 304 ? luaF_getlocalname(p, t + 1, pc)
305 : getstr(p->upvalues[t].name); 305 : getstr(p->upvalues[t].name);
306 kname(p, k, a, what, name); 306 kname(p, k, a, what, name);
307 what = (tabname && strcmp(tabname, "_ENV") == 0) ? "global" : "field"; 307 what = (tabname == getstr(G(L)->envn)) ? "global" : "field";
308 } 308 }
309 break; 309 break;
310 } 310 }
diff --git a/llex.h b/llex.h
index 7eb2f274..276802e0 100644
--- a/llex.h
+++ b/llex.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.h,v 1.62 2009/10/11 20:02:19 roberto Exp roberto $ 2** $Id: llex.h,v 1.63 2010/03/08 16:55:52 roberto Exp roberto $
3** Lexical Analyzer 3** Lexical Analyzer
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -60,7 +60,6 @@ typedef struct LexState {
60 Mbuffer *buff; /* buffer for tokens */ 60 Mbuffer *buff; /* buffer for tokens */
61 struct Varlist *varl; /* list of all active local variables */ 61 struct Varlist *varl; /* list of all active local variables */
62 TString *source; /* current source name */ 62 TString *source; /* current source name */
63 TString *envn; /* name of environment variable */
64 char decpoint; /* locale decimal point */ 63 char decpoint; /* locale decimal point */
65} LexState; 64} LexState;
66 65
diff --git a/lparser.c b/lparser.c
index 6ce0bdbf..12978acb 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 2.78 2010/03/08 16:55:52 roberto Exp roberto $ 2** $Id: lparser.c,v 2.79 2010/03/12 19:14:06 roberto Exp roberto $
3** Lua Parser 3** Lua Parser
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -288,7 +288,7 @@ static void singlevar (LexState *ls, expdesc *var) {
288 FuncState *fs = ls->fs; 288 FuncState *fs = ls->fs;
289 if (singlevaraux(fs, varname, var, 1) == VVOID) { /* global name? */ 289 if (singlevaraux(fs, varname, var, 1) == VVOID) { /* global name? */
290 expdesc key; 290 expdesc key;
291 singlevaraux(fs, ls->envn, var, 1); /* get _ENV variable */ 291 singlevaraux(fs, G(ls->L)->envn, var, 1); /* get _ENV variable */
292 lua_assert(var->k == VLOCAL || var->k == VUPVAL); 292 lua_assert(var->k == VLOCAL || var->k == VUPVAL);
293 codestring(ls, &key, varname); /* key is variable name */ 293 codestring(ls, &key, varname); /* key is variable name */
294 luaK_indexed(fs, var, &key); /* env[varname] */ 294 luaK_indexed(fs, var, &key); /* env[varname] */
@@ -433,11 +433,8 @@ static void open_mainfunc (lua_State *L, LexState *ls, FuncState *fs) {
433 expdesc v; 433 expdesc v;
434 open_func(ls, fs); 434 open_func(ls, fs);
435 fs->f->is_vararg = 1; /* main function is always vararg */ 435 fs->f->is_vararg = 1; /* main function is always vararg */
436 ls->envn = luaS_new(L, "_ENV"); /* create '_ENV' string */
437 setsvalue2s(L, L->top++, ls->envn); /* anchor it */
438 init_exp(&v, VLOCAL, 0); 436 init_exp(&v, VLOCAL, 0);
439 newupvalue(fs, ls->envn, &v); /* create '_ENV' upvalue */ 437 newupvalue(fs, G(L)->envn, &v); /* create '_ENV' upvalue */
440 L->top--; /* now string is anchored as an upvalue name */
441} 438}
442 439
443 440
diff --git a/lstate.c b/lstate.c
index 2fc282e7..9685f2a5 100644
--- a/lstate.c
+++ b/lstate.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.c,v 2.67 2009/12/17 12:26:09 roberto Exp roberto $ 2** $Id: lstate.c,v 2.68 2009/12/22 15:32:50 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*/
@@ -161,6 +161,8 @@ static void f_luaopen (lua_State *L, void *ud) {
161 luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */ 161 luaS_resize(L, MINSTRTABSIZE); /* initial size of string table */
162 luaT_init(L); 162 luaT_init(L);
163 luaX_init(L); 163 luaX_init(L);
164 g->envn = luaS_new(L, "_ENV");
165 luaS_fix(g->envn); /* never collect this name */
164 luaS_fix(luaS_newliteral(L, MEMERRMSG)); 166 luaS_fix(luaS_newliteral(L, MEMERRMSG));
165 g->GCthreshold = 4*g->totalbytes; 167 g->GCthreshold = 4*g->totalbytes;
166} 168}
diff --git a/lstate.h b/lstate.h
index a6ea5546..eb0068fe 100644
--- a/lstate.h
+++ b/lstate.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lstate.h,v 2.52 2009/12/22 15:32:50 roberto Exp roberto $ 2** $Id: lstate.h,v 2.53 2010/02/09 11:55:37 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*/
@@ -144,6 +144,7 @@ typedef struct global_State {
144 const lua_Number *version; /* pointer to version number */ 144 const lua_Number *version; /* pointer to version number */
145 struct Table *mt[NUM_TAGS]; /* metatables for basic types */ 145 struct Table *mt[NUM_TAGS]; /* metatables for basic types */
146 TString *tmname[TM_N]; /* array with tag-method names */ 146 TString *tmname[TM_N]; /* array with tag-method names */
147 TString *envn; /* environment variable name */
147} global_State; 148} global_State;
148 149
149 150