mirror of https://github.com/rusefi/lua.git
name "_ENV" configurable through 'luaconf.h'
This commit is contained in:
parent
6828f6d427
commit
0df2238063
4
lapi.c
4
lapi.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lapi.c,v 2.134 2010/08/04 18:40:28 roberto Exp roberto $
|
** $Id: lapi.c,v 2.135 2010/09/03 14:14:01 roberto Exp roberto $
|
||||||
** Lua API
|
** Lua API
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -891,7 +891,7 @@ LUA_API int lua_load (lua_State *L, lua_Reader reader, void *data,
|
||||||
/* get global table from registry */
|
/* get global table from registry */
|
||||||
Table *reg = hvalue(&G(L)->l_registry);
|
Table *reg = hvalue(&G(L)->l_registry);
|
||||||
const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS);
|
const TValue *gt = luaH_getint(reg, LUA_RIDX_GLOBALS);
|
||||||
/* set global table as 1st upvalue of 'f' (may be _ENV) */
|
/* set global table as 1st upvalue of 'f' (may be LUA_ENV) */
|
||||||
setobj(L, f->l.upvals[0]->v, gt);
|
setobj(L, f->l.upvals[0]->v, gt);
|
||||||
luaC_barrier(L, f->l.upvals[0], gt);
|
luaC_barrier(L, f->l.upvals[0], gt);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lbaselib.c,v 1.247 2010/08/23 18:03:11 roberto Exp roberto $
|
** $Id: lbaselib.c,v 1.248 2010/09/03 14:14:01 roberto Exp roberto $
|
||||||
** Basic library
|
** Basic library
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -336,7 +336,7 @@ static int luaB_loadin (lua_State *L) {
|
||||||
const char *name;
|
const char *name;
|
||||||
lua_pushvalue(L, 1); /* environment for loaded function */
|
lua_pushvalue(L, 1); /* environment for loaded function */
|
||||||
name = lua_setupvalue(L, -2, 1);
|
name = lua_setupvalue(L, -2, 1);
|
||||||
if (name == NULL || strcmp(name, "_ENV") != 0)
|
if (name == NULL || strcmp(name, LUA_ENV) != 0)
|
||||||
luaL_error(L, "loaded chunk does not have environment upvalue");
|
luaL_error(L, "loaded chunk does not have environment upvalue");
|
||||||
}
|
}
|
||||||
return n;
|
return n;
|
||||||
|
|
4
ldebug.c
4
ldebug.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: ldebug.c,v 2.71 2010/06/16 13:44:36 roberto Exp roberto $
|
** $Id: ldebug.c,v 2.72 2010/06/21 16:30:12 roberto Exp roberto $
|
||||||
** Debug Interface
|
** Debug Interface
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -315,7 +315,7 @@ static const char *getobjname (lua_State *L, CallInfo *ci, int reg,
|
||||||
? luaF_getlocalname(p, t + 1, pc)
|
? luaF_getlocalname(p, t + 1, pc)
|
||||||
: getstr(p->upvalues[t].name);
|
: getstr(p->upvalues[t].name);
|
||||||
kname(p, k, a, what, name);
|
kname(p, k, a, what, name);
|
||||||
what = (vn && strcmp(vn, "_ENV") == 0) ? "global" : "field";
|
what = (vn && strcmp(vn, LUA_ENV) == 0) ? "global" : "field";
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
4
llex.c
4
llex.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: llex.c,v 2.36 2010/04/05 16:35:37 roberto Exp roberto $
|
** $Id: llex.c,v 2.37 2010/04/16 12:31:07 roberto Exp roberto $
|
||||||
** Lexical Analyzer
|
** Lexical Analyzer
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -161,7 +161,7 @@ void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source) {
|
||||||
ls->linenumber = 1;
|
ls->linenumber = 1;
|
||||||
ls->lastline = 1;
|
ls->lastline = 1;
|
||||||
ls->source = source;
|
ls->source = source;
|
||||||
ls->envn = luaS_new(L, "_ENV"); /* create env name */
|
ls->envn = luaS_new(L, LUA_ENV); /* create env name */
|
||||||
luaS_fix(ls->envn); /* never collect this name */
|
luaS_fix(ls->envn); /* never collect this name */
|
||||||
luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */
|
luaZ_resizebuffer(ls->L, ls->buff, LUA_MINBUFFER); /* initialize buffer */
|
||||||
next(ls); /* read first char */
|
next(ls); /* read first char */
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: loadlib.c,v 1.89 2010/07/28 15:51:59 roberto Exp roberto $
|
** $Id: loadlib.c,v 1.90 2010/08/02 17:14:48 roberto Exp roberto $
|
||||||
** Dynamic library loader for Lua
|
** Dynamic library loader for Lua
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
**
|
**
|
||||||
|
@ -496,7 +496,7 @@ static int ll_require (lua_State *L) {
|
||||||
#if defined(LUA_COMPAT_MODULE)
|
#if defined(LUA_COMPAT_MODULE)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** changes the _ENV variable of calling function
|
** changes the environment variable of calling function
|
||||||
*/
|
*/
|
||||||
static void set_env (lua_State *L) {
|
static void set_env (lua_State *L) {
|
||||||
lua_Debug ar;
|
lua_Debug ar;
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lparser.c,v 2.90 2010/07/07 16:27:29 roberto Exp roberto $
|
** $Id: lparser.c,v 2.91 2010/08/23 17:32:34 roberto Exp roberto $
|
||||||
** Lua Parser
|
** Lua Parser
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -289,7 +289,7 @@ static void singlevar (LexState *ls, expdesc *var) {
|
||||||
FuncState *fs = ls->fs;
|
FuncState *fs = ls->fs;
|
||||||
if (singlevaraux(fs, varname, var, 1) == VVOID) { /* global name? */
|
if (singlevaraux(fs, varname, var, 1) == VVOID) { /* global name? */
|
||||||
expdesc key;
|
expdesc key;
|
||||||
singlevaraux(fs, ls->envn, var, 1); /* get _ENV variable */
|
singlevaraux(fs, ls->envn, var, 1); /* get environment variable */
|
||||||
lua_assert(var->k == VLOCAL || var->k == VUPVAL);
|
lua_assert(var->k == VLOCAL || var->k == VUPVAL);
|
||||||
codestring(ls, &key, varname); /* key is variable name */
|
codestring(ls, &key, varname); /* key is variable name */
|
||||||
luaK_indexed(fs, var, &key); /* env[varname] */
|
luaK_indexed(fs, var, &key); /* env[varname] */
|
||||||
|
@ -433,14 +433,14 @@ static void close_func (LexState *ls) {
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** opens the main function, which is a regular vararg function with an
|
** opens the main function, which is a regular vararg function with an
|
||||||
** upvalue named '_ENV'
|
** upvalue named LUA_ENV
|
||||||
*/
|
*/
|
||||||
static void open_mainfunc (LexState *ls, FuncState *fs) {
|
static void open_mainfunc (LexState *ls, FuncState *fs) {
|
||||||
expdesc v;
|
expdesc v;
|
||||||
open_func(ls, fs);
|
open_func(ls, fs);
|
||||||
fs->f->is_vararg = 1; /* main function is always vararg */
|
fs->f->is_vararg = 1; /* main function is always vararg */
|
||||||
init_exp(&v, VLOCAL, 0);
|
init_exp(&v, VLOCAL, 0);
|
||||||
newupvalue(fs, ls->envn, &v); /* create '_ENV' upvalue */
|
newupvalue(fs, ls->envn, &v); /* create environment upvalue */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
10
luaconf.h
10
luaconf.h
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: luaconf.h,v 1.141 2010/07/25 15:02:41 roberto Exp roberto $
|
** $Id: luaconf.h,v 1.142 2010/07/28 15:51:59 roberto Exp roberto $
|
||||||
** Configuration file for Lua
|
** Configuration file for Lua
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -115,6 +115,14 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
@@ LUA_ENV is the name of the variable that holds the current
|
||||||
|
@@ environment, used to access global names.
|
||||||
|
** CHANGE it if you do not like this name.
|
||||||
|
*/
|
||||||
|
#define LUA_ENV "_ENV"
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ LUA_API is a mark for all core API functions.
|
@@ LUA_API is a mark for all core API functions.
|
||||||
@@ LUALIB_API is a mark for all auxiliary library functions.
|
@@ LUALIB_API is a mark for all auxiliary library functions.
|
||||||
|
|
Loading…
Reference in New Issue