From 94c1b3a8eef6778cf995b906d77c0c066c6d55f3 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 12 Jan 2017 15:14:26 -0200 Subject: Handling of LUA_PATH/LUA_CPATH moved back to 'package' library to avoid incompatibilites with previous releases --- lua.c | 93 ++++--------------------------------------------------------------- 1 file changed, 5 insertions(+), 88 deletions(-) (limited to 'lua.c') diff --git a/lua.c b/lua.c index 2ca9a3a5..62de0f58 100644 --- a/lua.c +++ b/lua.c @@ -1,5 +1,5 @@ /* -** $Id: lua.c,v 1.228 2016/12/13 15:50:58 roberto Exp roberto $ +** $Id: lua.c,v 1.229 2016/12/22 13:08:50 roberto Exp roberto $ ** Lua stand-alone interpreter ** See Copyright Notice in lua.h */ @@ -20,8 +20,6 @@ #include "lualib.h" -#define LUA_VERSUFFIX "_" LUA_VERSION_MAJOR "_" LUA_VERSION_MINOR - #if !defined(LUA_PROMPT) #define LUA_PROMPT "> " @@ -534,88 +532,6 @@ static int runargs (lua_State *L, char **argv, int n) { -/* -** {================================================================== -** Set Paths -** =================================================================== -*/ - -/* -** LUA_PATH_VAR and LUA_CPATH_VAR are the names of the environment -** variables that Lua check to set its paths. -*/ -#if !defined(LUA_PATH_VAR) -#define LUA_PATH_VAR "LUA_PATH" -#endif - -#if !defined(LUA_CPATH_VAR) -#define LUA_CPATH_VAR "LUA_CPATH" -#endif - -#define LUA_PATHVARVERSION LUA_PATH_VAR LUA_VERSUFFIX -#define LUA_CPATHVARVERSION LUA_CPATH_VAR LUA_VERSUFFIX - - -#define AUXMARK "\1" /* auxiliary mark */ - - -#if defined(LUA_USE_WINDOWS) - - -/* -** Replace in the path (on the top of the stack) any occurrence -** of LUA_EXEC_DIR with the executable's path. -*/ -static void setprogdir (lua_State *L) { - char buff[MAX_PATH + 1]; - char *lb; - DWORD nsize = sizeof(buff)/sizeof(char); - DWORD n = GetModuleFileNameA(NULL, buff, nsize); /* get exec. name */ - if (n == 0 || n == nsize || (lb = strrchr(buff, '\\')) == NULL) - luaL_error(L, "unable to get ModuleFileName"); - else { - *lb = '\0'; /* cut name on the last '\\' to get the path */ - luaL_gsub(L, lua_tostring(L, -1), LUA_EXEC_DIR, buff); - lua_remove(L, -2); /* remove original string */ - } -} - -#else - -#define setprogdir(L) ((void)0) - -#endif - -/* -** Change a path according to corresponding environment variables -*/ -static void chgpath (lua_State *L, const char *fieldname, - const char *envname1, - const char *envname2, - int noenv) { - const char *path = getenv(envname1); - lua_getglobal(L, LUA_LOADLIBNAME); /* get 'package' table */ - lua_getfield(L, -1, fieldname); /* get original path */ - if (path == NULL) /* no environment variable? */ - path = getenv(envname2); /* try alternative name */ - if (path == NULL || noenv) /* no environment variable? */ - lua_pushvalue(L, -1); /* use original value */ - else { - const char *def = lua_tostring(L, -1); /* default path */ - /* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */ - path = luaL_gsub(L, path, LUA_PATH_SEP LUA_PATH_SEP, - LUA_PATH_SEP AUXMARK LUA_PATH_SEP); - luaL_gsub(L, path, AUXMARK, def); - lua_remove(L, -2); /* remove result from 1st 'gsub' */ - } - setprogdir(L); - lua_setfield(L, -3, fieldname); /* set path value */ - lua_pop(L, 2); /* pop 'package' table and original path */ -} - -/* }================================================================== */ - - static int handle_luainit (lua_State *L) { const char *name = "=" LUA_INITVARVERSION; const char *init = getenv(name + 1); @@ -648,10 +564,11 @@ static int pmain (lua_State *L) { } if (args & has_v) /* option '-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"); + } luaL_openlibs(L); /* open standard libraries */ - /* change paths according to env variables */ - chgpath(L, "path", LUA_PATHVARVERSION, LUA_PATH_VAR, (args & has_E)); - chgpath(L, "cpath", LUA_CPATHVARVERSION, LUA_CPATH_VAR, (args & has_E)); createargtable(L, argv, argc, script); /* create table 'arg' */ if (!(args & has_E)) { /* no option '-E'? */ if (handle_luainit(L) != LUA_OK) /* run LUA_INIT */ -- cgit v1.2.3-55-g6feb