diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-12-12 14:34:03 -0200 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2011-12-12 14:34:03 -0200 |
commit | e2fc2ce8dfe107d1e2742b459c2aaf137227bbc1 (patch) | |
tree | f306695aadb321d5aac40c183cd1e1f6c0776b10 | |
parent | a241b6cb3c7d14da5b5cf5c2305f8f840af38f19 (diff) | |
download | lua-e2fc2ce8dfe107d1e2742b459c2aaf137227bbc1.tar.gz lua-e2fc2ce8dfe107d1e2742b459c2aaf137227bbc1.tar.bz2 lua-e2fc2ce8dfe107d1e2742b459c2aaf137227bbc1.zip |
new way to handle -E option (write a mark in the registry to avoidv5.2.0
reading environment variables)
-rw-r--r-- | loadlib.c | 17 | ||||
-rw-r--r-- | lua.c | 23 |
2 files changed, 22 insertions, 18 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: loadlib.c,v 1.106 2011/11/28 17:27:51 roberto Exp roberto $ | 2 | ** $Id: loadlib.c,v 1.107 2011/11/30 12:58:57 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 | ** |
@@ -615,12 +615,25 @@ static int ll_seeall (lua_State *L) { | |||
615 | /* auxiliary mark (for internal use) */ | 615 | /* auxiliary mark (for internal use) */ |
616 | #define AUXMARK "\1" | 616 | #define AUXMARK "\1" |
617 | 617 | ||
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 | |||
618 | static void setpath (lua_State *L, const char *fieldname, const char *envname1, | 631 | static void setpath (lua_State *L, const char *fieldname, const char *envname1, |
619 | const char *envname2, const char *def) { | 632 | const char *envname2, const char *def) { |
620 | const char *path = getenv(envname1); | 633 | const char *path = getenv(envname1); |
621 | if (path == NULL) /* no environment variable? */ | 634 | if (path == NULL) /* no environment variable? */ |
622 | path = getenv(envname2); /* try alternative name */ | 635 | path = getenv(envname2); /* try alternative name */ |
623 | if (path == NULL) /* no environment variable? */ | 636 | if (path == NULL || noenv(L)) /* no environment variable? */ |
624 | lua_pushstring(L, def); /* use default */ | 637 | lua_pushstring(L, def); /* use default */ |
625 | else { | 638 | else { |
626 | /* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */ | 639 | /* replace ";;" by ";AUXMARK;" and then AUXMARK by default path */ |
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: lua.c,v 1.201 2011/08/04 18:16:16 roberto Exp roberto $ | 2 | ** $Id: lua.c,v 1.202 2011/08/17 20:19:52 roberto Exp roberto $ |
3 | ** Lua stand-alone interpreter | 3 | ** Lua stand-alone interpreter |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -439,18 +439,6 @@ static int handle_luainit (lua_State *L) { | |||
439 | } | 439 | } |
440 | 440 | ||
441 | 441 | ||
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 | |||
454 | static int pmain (lua_State *L) { | 442 | static int pmain (lua_State *L) { |
455 | int argc = (int)lua_tointeger(L, 1); | 443 | int argc = (int)lua_tointeger(L, 1); |
456 | char **argv = (char **)lua_touserdata(L, 2); | 444 | char **argv = (char **)lua_touserdata(L, 2); |
@@ -464,14 +452,17 @@ static int pmain (lua_State *L) { | |||
464 | return 0; | 452 | return 0; |
465 | } | 453 | } |
466 | if (args[has_v]) print_version(); | 454 | 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 | } | ||
467 | /* open standard libraries */ | 459 | /* open standard libraries */ |
468 | luaL_checkversion(L); | 460 | luaL_checkversion(L); |
469 | lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ | 461 | lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */ |
470 | luaL_openlibs(L); /* open libraries */ | 462 | luaL_openlibs(L); /* open libraries */ |
471 | lua_gc(L, LUA_GCRESTART, 0); | 463 | lua_gc(L, LUA_GCRESTART, 0); |
472 | if (args[has_E]) /* avoid LUA_INIT? */ | 464 | if (!args[has_E] && handle_luainit(L) != LUA_OK) |
473 | resetpaths(L); | 465 | return 0; /* error running LUA_INIT */ |
474 | else if (handle_luainit(L) != LUA_OK) return 0; | ||
475 | /* execute arguments -e and -l */ | 466 | /* execute arguments -e and -l */ |
476 | if (!runargs(L, argv, (script > 0) ? script : argc)) return 0; | 467 | if (!runargs(L, argv, (script > 0) ? script : argc)) return 0; |
477 | /* execute main script (if there is one) */ | 468 | /* execute main script (if there is one) */ |