aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Pall <mike>2012-07-16 22:47:01 +0200
committerMike Pall <mike>2012-07-16 22:47:01 +0200
commit63bb052bbef88821cc7b24a68a680dc821bc0fb2 (patch)
tree39fd0a1369e8448383d69231b31272f6e76d2c6b
parentbf2d4acf005e301ee593d9b73402967a339aa220 (diff)
downloadluajit-63bb052bbef88821cc7b24a68a680dc821bc0fb2.tar.gz
luajit-63bb052bbef88821cc7b24a68a680dc821bc0fb2.tar.bz2
luajit-63bb052bbef88821cc7b24a68a680dc821bc0fb2.zip
From Lua 5.2: Add -E command line option (ignore env vars).
-rw-r--r--etc/luajit.13
-rw-r--r--src/lib_package.c12
-rw-r--r--src/luajit.c26
3 files changed, 30 insertions, 11 deletions
diff --git a/etc/luajit.1 b/etc/luajit.1
index bd1074a0..474147c5 100644
--- a/etc/luajit.1
+++ b/etc/luajit.1
@@ -41,6 +41,9 @@ Run in interactive mode.
41.B "\-v" 41.B "\-v"
42Show \fBLuaJIT\fR version. 42Show \fBLuaJIT\fR version.
43.TP 43.TP
44.B "\-E"
45Ignore environment variables.
46.TP
44.B "\-\-" 47.B "\-\-"
45Stop processing options. 48Stop processing options.
46.TP 49.TP
diff --git a/src/lib_package.c b/src/lib_package.c
index 7435f6dc..c04253aa 100644
--- a/src/lib_package.c
+++ b/src/lib_package.c
@@ -517,7 +517,7 @@ static int lj_cf_package_seeall(lua_State *L)
517#define AUXMARK "\1" 517#define AUXMARK "\1"
518 518
519static void setpath(lua_State *L, const char *fieldname, const char *envname, 519static void setpath(lua_State *L, const char *fieldname, const char *envname,
520 const char *def) 520 const char *def, int noenv)
521{ 521{
522#if LJ_TARGET_CONSOLE 522#if LJ_TARGET_CONSOLE
523 const char *path = NULL; 523 const char *path = NULL;
@@ -525,7 +525,7 @@ static void setpath(lua_State *L, const char *fieldname, const char *envname,
525#else 525#else
526 const char *path = getenv(envname); 526 const char *path = getenv(envname);
527#endif 527#endif
528 if (path == NULL) { 528 if (path == NULL || noenv) {
529 lua_pushstring(L, def); 529 lua_pushstring(L, def);
530 } else { 530 } else {
531 path = luaL_gsub(L, path, LUA_PATHSEP LUA_PATHSEP, 531 path = luaL_gsub(L, path, LUA_PATHSEP LUA_PATHSEP,
@@ -562,6 +562,7 @@ static const lua_CFunction package_loaders[] =
562LUALIB_API int luaopen_package(lua_State *L) 562LUALIB_API int luaopen_package(lua_State *L)
563{ 563{
564 int i; 564 int i;
565 int noenv;
565 luaL_newmetatable(L, "_LOADLIB"); 566 luaL_newmetatable(L, "_LOADLIB");
566 lj_lib_pushcf(L, lj_cf_package_unloadlib, 1); 567 lj_lib_pushcf(L, lj_cf_package_unloadlib, 1);
567 lua_setfield(L, -2, "__gc"); 568 lua_setfield(L, -2, "__gc");
@@ -574,8 +575,11 @@ LUALIB_API int luaopen_package(lua_State *L)
574 lua_rawseti(L, -2, i+1); 575 lua_rawseti(L, -2, i+1);
575 } 576 }
576 lua_setfield(L, -2, "loaders"); 577 lua_setfield(L, -2, "loaders");
577 setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT); 578 lua_getfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
578 setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT); 579 noenv = lua_toboolean(L, -1);
580 lua_pop(L, 1);
581 setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT, noenv);
582 setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT, noenv);
579 lua_pushliteral(L, LUA_PATH_CONFIG); 583 lua_pushliteral(L, LUA_PATH_CONFIG);
580 lua_setfield(L, -2, "config"); 584 lua_setfield(L, -2, "config");
581 luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 16); 585 luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 16);
diff --git a/src/luajit.c b/src/luajit.c
index b7d9d0c1..22628aaf 100644
--- a/src/luajit.c
+++ b/src/luajit.c
@@ -71,6 +71,7 @@ static void print_usage(void)
71 " -O[opt] Control LuaJIT optimizations.\n" 71 " -O[opt] Control LuaJIT optimizations.\n"
72 " -i Enter interactive mode after executing " LUA_QL("script") ".\n" 72 " -i Enter interactive mode after executing " LUA_QL("script") ".\n"
73 " -v Show version information.\n" 73 " -v Show version information.\n"
74 " -E Ignore environment variables.\n"
74 " -- Stop handling options.\n" 75 " -- Stop handling options.\n"
75 " - Execute stdin and stop handling options.\n" 76 " - Execute stdin and stop handling options.\n"
76 , 77 ,
@@ -406,6 +407,7 @@ static int dobytecode(lua_State *L, char **argv)
406#define FLAGS_VERSION 2 407#define FLAGS_VERSION 2
407#define FLAGS_EXEC 4 408#define FLAGS_EXEC 4
408#define FLAGS_OPTION 8 409#define FLAGS_OPTION 8
410#define FLAGS_NOENV 16
409 411
410static int collectargs(char **argv, int *flags) 412static int collectargs(char **argv, int *flags)
411{ 413{
@@ -442,6 +444,9 @@ static int collectargs(char **argv, int *flags)
442 if (*flags) return -1; 444 if (*flags) return -1;
443 *flags |= FLAGS_EXEC; 445 *flags |= FLAGS_EXEC;
444 return 0; 446 return 0;
447 case 'E':
448 *flags |= FLAGS_NOENV;
449 break;
445 default: return -1; /* invalid option */ 450 default: return -1; /* invalid option */
446 } 451 }
447 } 452 }
@@ -521,23 +526,30 @@ static int pmain(lua_State *L)
521 globalL = L; 526 globalL = L;
522 if (argv[0] && argv[0][0]) progname = argv[0]; 527 if (argv[0] && argv[0][0]) progname = argv[0];
523 LUAJIT_VERSION_SYM(); /* linker-enforced version check */ 528 LUAJIT_VERSION_SYM(); /* linker-enforced version check */
524 lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */
525 luaL_openlibs(L); /* open libraries */
526 lua_gc(L, LUA_GCRESTART, -1);
527 s->status = handle_luainit(L);
528 if (s->status != 0) return 0;
529 script = collectargs(argv, &flags); 529 script = collectargs(argv, &flags);
530 if (script < 0) { /* invalid args? */ 530 if (script < 0) { /* invalid args? */
531 print_usage(); 531 print_usage();
532 s->status = 1; 532 s->status = 1;
533 return 0; 533 return 0;
534 } 534 }
535 if ((flags & FLAGS_NOENV)) {
536 lua_pushboolean(L, 1);
537 lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
538 }
539 lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */
540 luaL_openlibs(L); /* open libraries */
541 lua_gc(L, LUA_GCRESTART, -1);
542 if (!(flags & FLAGS_NOENV)) {
543 s->status = handle_luainit(L);
544 if (s->status != 0) return 0;
545 }
535 if ((flags & FLAGS_VERSION)) print_version(); 546 if ((flags & FLAGS_VERSION)) print_version();
536 s->status = runargs(L, argv, (script > 0) ? script : s->argc); 547 s->status = runargs(L, argv, (script > 0) ? script : s->argc);
537 if (s->status != 0) return 0; 548 if (s->status != 0) return 0;
538 if (script) 549 if (script) {
539 s->status = handle_script(L, argv, script); 550 s->status = handle_script(L, argv, script);
540 if (s->status != 0) return 0; 551 if (s->status != 0) return 0;
552 }
541 if ((flags & FLAGS_INTERACTIVE)) { 553 if ((flags & FLAGS_INTERACTIVE)) {
542 print_jit_status(L); 554 print_jit_status(L);
543 dotty(L); 555 dotty(L);