History

Lua 5.2.0

Lua Team committed 14 years ago

Commit 32bd3eb1 parent 798bf685 files · +40 −31Browse files

Showing the changes to src (2 of 5 files). Show all

Unified · Split

2 files
  1. src/loadlib.c +15 −2
  2. src/lua.c +7 −16
src/loadlib.c+15−2
@@ -1,5 +1,5 @@
11 /*
2−** $Id: loadlib.c,v 1.107 2011/11/30 12:58:57 roberto Exp $
2+** $Id: loadlib.c,v 1.108 2011/12/12 16:34:03 roberto Exp $
33 ** Dynamic library loader for Lua
44 ** See Copyright Notice in lua.h
55 **
@@ -615,12 +615,25 @@ static int ll_seeall (lua_State *L) { · 609 unmodified lines
615615 /* auxiliary mark (for internal use) */
616616 #define AUXMARK "\1"
617617
618+
619+/*
620+** return registry.LUA_NOENV as a boolean
621+*/
622+static int noenv (lua_State *L) {
623+ int b;
624+ lua_getfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
625+ b = lua_toboolean(L, -1);
626+ lua_pop(L, 1); /* remove value */
627+ return b;
628+}
629+
630+
618631 static void setpath (lua_State *L, const char *fieldname, const char *envname1,
619632 const char *envname2, const char *def) {
620633 const char *path = getenv(envname1);
621634 if (path == NULL) /* no environment variable? */
622635 path = getenv(envname2); /* try alternative name */
623− if (path == NULL) /* no environment variable? */
636+ if (path == NULL || noenv(L)) /* no environment variable? */
624637 lua_pushstring(L, def); /* use default */
625638 else {
626639 /* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */
src/lua.c+7−16
@@ -1,5 +1,5 @@
11 /*
2−** $Id: lua.c,v 1.202 2011/08/17 20:19:52 roberto Exp $
2+** $Id: lua.c,v 1.203 2011/12/12 16:34:03 roberto Exp $
33 ** Lua stand-alone interpreter
44 ** See Copyright Notice in lua.h
55 */
@@ -439,18 +439,6 @@ static int handle_luainit (lua_State *L) { · 433 unmodified lines
439439 }
440440
441441
442−static void resetpaths (lua_State *L) {
443− lua_getglobal(L, "package");
444− if (!lua_istable(L, -1)) /* no module 'package'? */
445− return; /* nothing to be done */
446− lua_pushliteral(L, LUA_PATH_DEFAULT);
447− lua_setfield(L, -2, "path"); /* package.path = default */
448− lua_pushliteral(L, LUA_CPATH_DEFAULT);
449− lua_setfield(L, -2, "cpath"); /* package.cpath = default */
450− lua_pop(L, 1); /* remove 'package' */
451−}
452−
453−
454442 static int pmain (lua_State *L) {
455443 int argc = (int)lua_tointeger(L, 1);
456444 char **argv = (char **)lua_touserdata(L, 2);
@@ -464,14 +452,17 @@ static int pmain (lua_State *L) { · 7 unmodified lines
464452 return 0;
465453 }
466454 if (args[has_v]) print_version();
455+ if (args[has_E]) { /* option '-E'? */
456+ lua_pushboolean(L, 1); /* signal for libraries to ignore env. vars. */
457+ lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
458+ }
467459 /* open standard libraries */
468460 luaL_checkversion(L);
469461 lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */
470462 luaL_openlibs(L); /* open libraries */
471463 lua_gc(L, LUA_GCRESTART, 0);
472− if (args[has_E]) /* avoid LUA_INIT? */
473− resetpaths(L);
474− else if (handle_luainit(L) != LUA_OK) return 0;
464+ if (!args[has_E] && handle_luainit(L) != LUA_OK)
465+ return 0; /* error running LUA_INIT */
475466 /* execute arguments -e and -l */
476467 if (!runargs(L, argv, (script > 0) ? script : argc)) return 0;
477468 /* execute main script (if there is one) */