aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-09-07 16:21:39 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2010-09-07 16:21:39 -0300
commit0df2238063f3e5b1a12c5272484f2afd45a2a2f1 (patch)
tree04361bb15edb5dbeba28ecd0103a0f29807112ad
parent6828f6d42786de735d6696da8cccbb47c8bad347 (diff)
downloadlua-0df2238063f3e5b1a12c5272484f2afd45a2a2f1.tar.gz
lua-0df2238063f3e5b1a12c5272484f2afd45a2a2f1.tar.bz2
lua-0df2238063f3e5b1a12c5272484f2afd45a2a2f1.zip
name "_ENV" configurable through 'luaconf.h'
-rw-r--r--lapi.c4
-rw-r--r--lbaselib.c4
-rw-r--r--ldebug.c4
-rw-r--r--llex.c4
-rw-r--r--loadlib.c4
-rw-r--r--lparser.c8
-rw-r--r--luaconf.h10
7 files changed, 23 insertions, 15 deletions
diff --git a/lapi.c b/lapi.c
index b19ac922..aacfd93c 100644
--- a/lapi.c
+++ b/lapi.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lapi.c,v 2.134 2010/08/04 18:40:28 roberto Exp roberto $ 2** $Id: lapi.c,v 2.135 2010/09/03 14:14: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*/
@@ -891,7 +891,7 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,
891 /* get global table from registry */ 891 /* get global table from registry */
892 Table *reg = hvalue(&G(L)->l_registry); 892 Table *reg = hvalue(&G(L)->l_registry);
893 const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS); 893 const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS);
894 /* set global table as 1st upvalue of 'f' (may be _ENV) */ 894 /* set global table as 1st upvalue of 'f' (may be LUA_ENV) */
895 setobj(L, f->l.upvals[0]->v, gt); 895 setobj(L, f->l.upvals[0]->v, gt);
896 luaC_barrier(L, f->l.upvals[0], gt); 896 luaC_barrier(L, f->l.upvals[0], gt);
897 } 897 }
diff --git a/lbaselib.c b/lbaselib.c
index b8dc6b50..e3fc8d8b 100644
--- a/lbaselib.c
+++ b/lbaselib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lbaselib.c,v 1.247 2010/08/23 18:03:11 roberto Exp roberto $ 2** $Id: lbaselib.c,v 1.248 2010/09/03 14:14: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*/
@@ -336,7 +336,7 @@ static int luaB_loadin (lua_State *L) {
336 const char *name; 336 const char *name;
337 lua_pushvalue(L, 1); /* environment for loaded function */ 337 lua_pushvalue(L, 1); /* environment for loaded function */
338 name = lua_setupvalue(L, -2, 1); 338 name = lua_setupvalue(L, -2, 1);
339 if (name == NULL || strcmp(name, "_ENV") != 0) 339 if (name == NULL || strcmp(name, LUA_ENV) != 0)
340 luaL_error(L, "loaded chunk does not have environment upvalue"); 340 luaL_error(L, "loaded chunk does not have environment upvalue");
341 } 341 }
342 return n; 342 return n;
diff --git a/ldebug.c b/ldebug.c
index fcead7ce..01aab131 100644
--- a/ldebug.c
+++ b/ldebug.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: ldebug.c,v 2.71 2010/06/16 13:44:36 roberto Exp roberto $ 2** $Id: ldebug.c,v 2.72 2010/06/21 16:30:12 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*/
@@ -315,7 +315,7 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int reg,
315 ? luaF_getlocalname(p, t + 1, pc) 315 ? luaF_getlocalname(p, t + 1, pc)
316 : getstr(p->upvalues[t].name); 316 : getstr(p->upvalues[t].name);
317 kname(p, k, a, what, name); 317 kname(p, k, a, what, name);
318 what = (vn && strcmp(vn, "_ENV") == 0) ? "global" : "field"; 318 what = (vn && strcmp(vn, LUA_ENV) == 0) ? "global" : "field";
319 } 319 }
320 break; 320 break;
321 } 321 }
diff --git a/llex.c b/llex.c
index 8ee4a7da..83ce856e 100644
--- a/llex.c
+++ b/llex.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: llex.c,v 2.36 2010/04/05 16:35:37 roberto Exp roberto $ 2** $Id: llex.c,v 2.37 2010/04/16 12:31:07 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*/
@@ -161,7 +161,7 @@ void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) {
161 ls->linenumber = 1; 161 ls->linenumber = 1;
162 ls->lastline = 1; 162 ls->lastline = 1;
163 ls->source = source; 163 ls->source = source;
164 ls->envn = luaS_new(L, "_ENV"); /* create env name */ 164 ls->envn = luaS_new(L, LUA_ENV); /* create env name */
165 luaS_fix(ls->envn); /* never collect this name */ 165 luaS_fix(ls->envn); /* never collect this name */
166 luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */ 166 luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */
167 next(ls); /* read first char */ 167 next(ls); /* read first char */
diff --git a/loadlib.c b/loadlib.c
index d46f4acd..c9d7625d 100644
--- a/loadlib.c
+++ b/loadlib.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: loadlib.c,v 1.89 2010/07/28 15:51:59 roberto Exp roberto $ 2** $Id: loadlib.c,v 1.90 2010/08/02 17:14:48 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**
@@ -496,7 +496,7 @@ static int ll_require (lua_State *L) {
496#if defined(LUA_COMPAT_MODULE) 496#if defined(LUA_COMPAT_MODULE)
497 497
498/* 498/*
499** changes the _ENV variable of calling function 499** changes the environment variable of calling function
500*/ 500*/
501static void set_env (lua_State *L) { 501static void set_env (lua_State *L) {
502 lua_Debug ar; 502 lua_Debug ar;
diff --git a/lparser.c b/lparser.c
index c042ddc8..27919b6a 100644
--- a/lparser.c
+++ b/lparser.c
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: lparser.c,v 2.90 2010/07/07 16:27:29 roberto Exp roberto $ 2** $Id: lparser.c,v 2.91 2010/08/23 17:32:34 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*/
@@ -289,7 +289,7 @@ static void singlevar (LexState *ls, expdesc *var) {
289 FuncState *fs = ls->fs; 289 FuncState *fs = ls->fs;
290 if (singlevaraux(fs, varname, var, 1) == VVOID) { /* global name? */ 290 if (singlevaraux(fs, varname, var, 1) == VVOID) { /* global name? */
291 expdesc key; 291 expdesc key;
292 singlevaraux(fs, ls->envn, var, 1); /* get _ENV variable */ 292 singlevaraux(fs, ls->envn, var, 1); /* get environment variable */
293 lua_assert(var->k == VLOCAL || var->k == VUPVAL); 293 lua_assert(var->k == VLOCAL || var->k == VUPVAL);
294 codestring(ls, &key, varname); /* key is variable name */ 294 codestring(ls, &key, varname); /* key is variable name */
295 luaK_indexed(fs, var, &key); /* env[varname] */ 295 luaK_indexed(fs, var, &key); /* env[varname] */
@@ -433,14 +433,14 @@ static void close_func (LexState *ls) {
433 433
434/* 434/*
435** opens the main function, which is a regular vararg function with an 435** opens the main function, which is a regular vararg function with an
436** upvalue named '_ENV' 436** upvalue named LUA_ENV
437*/ 437*/
438static void open_mainfunc (LexState *ls, FuncState *fs) { 438static void open_mainfunc (LexState *ls, FuncState *fs) {
439 expdesc v; 439 expdesc v;
440 open_func(ls, fs); 440 open_func(ls, fs);
441 fs->f->is_vararg = 1; /* main function is always vararg */ 441 fs->f->is_vararg = 1; /* main function is always vararg */
442 init_exp(&v, VLOCAL, 0); 442 init_exp(&v, VLOCAL, 0);
443 newupvalue(fs, ls->envn, &v); /* create '_ENV' upvalue */ 443 newupvalue(fs, ls->envn, &v); /* create environment upvalue */
444} 444}
445 445
446 446
diff --git a/luaconf.h b/luaconf.h
index ad4e65f9..1b881475 100644
--- a/luaconf.h
+++ b/luaconf.h
@@ -1,5 +1,5 @@
1/* 1/*
2** $Id: luaconf.h,v 1.141 2010/07/25 15:02:41 roberto Exp roberto $ 2** $Id: luaconf.h,v 1.142 2010/07/28 15:51:59 roberto Exp roberto $
3** Configuration file for Lua 3** Configuration file for Lua
4** See Copyright Notice in lua.h 4** See Copyright Notice in lua.h
5*/ 5*/
@@ -116,6 +116,14 @@
116 116
117 117
118/* 118/*
119@@ LUA_ENV is the name of the variable that holds the current
120@@ environment, used to access global names.
121** CHANGE it if you do not like this name.
122*/
123#define LUA_ENV "_ENV"
124
125
126/*
119@@ LUA_API is a mark for all core API functions. 127@@ LUA_API is a mark for all core API functions.
120@@ LUALIB_API is a mark for all auxiliary library functions. 128@@ LUALIB_API is a mark for all auxiliary library functions.
121@@ LUAMOD_API is a mark for all standard library opening functions. 129@@ LUAMOD_API is a mark for all standard library opening functions.