mirror of https://github.com/rusefi/lua.git
new way to handle -E option (write a mark in the registry to avoid
reading environment variables)
This commit is contained in:
parent
a241b6cb3c
commit
e2fc2ce8df
17
loadlib.c
17
loadlib.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: loadlib.c,v 1.106 2011/11/28 17:27:51 roberto Exp roberto $
|
** $Id: loadlib.c,v 1.107 2011/11/30 12:58:57 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
|
||||||
**
|
**
|
||||||
|
@ -615,12 +615,25 @@ static int ll_seeall (lua_State *L) {
|
||||||
/* auxiliary mark (for internal use) */
|
/* auxiliary mark (for internal use) */
|
||||||
#define AUXMARK "\1"
|
#define AUXMARK "\1"
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
** return registry.LUA_NOENV as a boolean
|
||||||
|
*/
|
||||||
|
static int noenv (lua_State *L) {
|
||||||
|
int b;
|
||||||
|
lua_getfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
|
||||||
|
b = lua_toboolean(L, -1);
|
||||||
|
lua_pop(L, 1); /* remove value */
|
||||||
|
return b;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static void setpath (lua_State *L, const char *fieldname, const char *envname1,
|
static void setpath (lua_State *L, const char *fieldname, const char *envname1,
|
||||||
const char *envname2, const char *def) {
|
const char *envname2, const char *def) {
|
||||||
const char *path = getenv(envname1);
|
const char *path = getenv(envname1);
|
||||||
if (path == NULL) /* no environment variable? */
|
if (path == NULL) /* no environment variable? */
|
||||||
path = getenv(envname2); /* try alternative name */
|
path = getenv(envname2); /* try alternative name */
|
||||||
if (path == NULL) /* no environment variable? */
|
if (path == NULL || noenv(L)) /* no environment variable? */
|
||||||
lua_pushstring(L, def); /* use default */
|
lua_pushstring(L, def); /* use default */
|
||||||
else {
|
else {
|
||||||
/* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */
|
/* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */
|
||||||
|
|
23
lua.c
23
lua.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: lua.c,v 1.201 2011/08/04 18:16:16 roberto Exp roberto $
|
** $Id: lua.c,v 1.202 2011/08/17 20:19:52 roberto Exp roberto $
|
||||||
** Lua stand-alone interpreter
|
** Lua stand-alone interpreter
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -439,18 +439,6 @@ static int handle_luainit (lua_State *L) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void resetpaths (lua_State *L) {
|
|
||||||
lua_getglobal(L, "package");
|
|
||||||
if (!lua_istable(L, -1)) /* no module 'package'? */
|
|
||||||
return; /* nothing to be done */
|
|
||||||
lua_pushliteral(L, LUA_PATH_DEFAULT);
|
|
||||||
lua_setfield(L, -2, "path"); /* package.path = default */
|
|
||||||
lua_pushliteral(L, LUA_CPATH_DEFAULT);
|
|
||||||
lua_setfield(L, -2, "cpath"); /* package.cpath = default */
|
|
||||||
lua_pop(L, 1); /* remove 'package' */
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static int pmain (lua_State *L) {
|
static int pmain (lua_State *L) {
|
||||||
int argc = (int)lua_tointeger(L, 1);
|
int argc = (int)lua_tointeger(L, 1);
|
||||||
char **argv = (char **)lua_touserdata(L, 2);
|
char **argv = (char **)lua_touserdata(L, 2);
|
||||||
|
@ -464,14 +452,17 @@ static int pmain (lua_State *L) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (args[has_v]) print_version();
|
if (args[has_v]) print_version();
|
||||||
|
if (args[has_E]) { /* option '-E'? */
|
||||||
|
lua_pushboolean(L, 1); /* signal for libraries to ignore env. vars. */
|
||||||
|
lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
|
||||||
|
}
|
||||||
/* open standard libraries */
|
/* open standard libraries */
|
||||||
luaL_checkversion(L);
|
luaL_checkversion(L);
|
||||||
lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */
|
lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */
|
||||||
luaL_openlibs(L); /* open libraries */
|
luaL_openlibs(L); /* open libraries */
|
||||||
lua_gc(L, LUA_GCRESTART, 0);
|
lua_gc(L, LUA_GCRESTART, 0);
|
||||||
if (args[has_E]) /* avoid LUA_INIT? */
|
if (!args[has_E] && handle_luainit(L) != LUA_OK)
|
||||||
resetpaths(L);
|
return 0; /* error running LUA_INIT */
|
||||||
else if (handle_luainit(L) != LUA_OK) return 0;
|
|
||||||
/* execute arguments -e and -l */
|
/* execute arguments -e and -l */
|
||||||
if (!runargs(L, argv, (script > 0) ? script : argc)) return 0;
|
if (!runargs(L, argv, (script > 0) ? script : argc)) return 0;
|
||||||
/* execute main script (if there is one) */
|
/* execute main script (if there is one) */
|
||||||
|
|
Loading…
Reference in New Issue