mirror of
https://github.com/LuaJIT/LuaJIT.git
synced 2025-02-07 23:24:09 +00:00
From Lua 5.2: Add -E command line option (ignore env vars).
This commit is contained in:
parent
bf2d4acf00
commit
63bb052bbe
@ -41,6 +41,9 @@ Run in interactive mode.
|
|||||||
.B "\-v"
|
.B "\-v"
|
||||||
Show \fBLuaJIT\fR version.
|
Show \fBLuaJIT\fR version.
|
||||||
.TP
|
.TP
|
||||||
|
.B "\-E"
|
||||||
|
Ignore environment variables.
|
||||||
|
.TP
|
||||||
.B "\-\-"
|
.B "\-\-"
|
||||||
Stop processing options.
|
Stop processing options.
|
||||||
.TP
|
.TP
|
||||||
|
@ -517,7 +517,7 @@ static int lj_cf_package_seeall(lua_State *L)
|
|||||||
#define AUXMARK "\1"
|
#define AUXMARK "\1"
|
||||||
|
|
||||||
static void setpath(lua_State *L, const char *fieldname, const char *envname,
|
static void setpath(lua_State *L, const char *fieldname, const char *envname,
|
||||||
const char *def)
|
const char *def, int noenv)
|
||||||
{
|
{
|
||||||
#if LJ_TARGET_CONSOLE
|
#if LJ_TARGET_CONSOLE
|
||||||
const char *path = NULL;
|
const char *path = NULL;
|
||||||
@ -525,7 +525,7 @@ static void setpath(lua_State *L, const char *fieldname, const char *envname,
|
|||||||
#else
|
#else
|
||||||
const char *path = getenv(envname);
|
const char *path = getenv(envname);
|
||||||
#endif
|
#endif
|
||||||
if (path == NULL) {
|
if (path == NULL || noenv) {
|
||||||
lua_pushstring(L, def);
|
lua_pushstring(L, def);
|
||||||
} else {
|
} else {
|
||||||
path = luaL_gsub(L, path, LUA_PATHSEP LUA_PATHSEP,
|
path = luaL_gsub(L, path, LUA_PATHSEP LUA_PATHSEP,
|
||||||
@ -562,6 +562,7 @@ static const lua_CFunction package_loaders[] =
|
|||||||
LUALIB_API int luaopen_package(lua_State *L)
|
LUALIB_API int luaopen_package(lua_State *L)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
int noenv;
|
||||||
luaL_newmetatable(L, "_LOADLIB");
|
luaL_newmetatable(L, "_LOADLIB");
|
||||||
lj_lib_pushcf(L, lj_cf_package_unloadlib, 1);
|
lj_lib_pushcf(L, lj_cf_package_unloadlib, 1);
|
||||||
lua_setfield(L, -2, "__gc");
|
lua_setfield(L, -2, "__gc");
|
||||||
@ -574,8 +575,11 @@ LUALIB_API int luaopen_package(lua_State *L)
|
|||||||
lua_rawseti(L, -2, i+1);
|
lua_rawseti(L, -2, i+1);
|
||||||
}
|
}
|
||||||
lua_setfield(L, -2, "loaders");
|
lua_setfield(L, -2, "loaders");
|
||||||
setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT);
|
lua_getfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
|
||||||
setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT);
|
noenv = lua_toboolean(L, -1);
|
||||||
|
lua_pop(L, 1);
|
||||||
|
setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT, noenv);
|
||||||
|
setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT, noenv);
|
||||||
lua_pushliteral(L, LUA_PATH_CONFIG);
|
lua_pushliteral(L, LUA_PATH_CONFIG);
|
||||||
lua_setfield(L, -2, "config");
|
lua_setfield(L, -2, "config");
|
||||||
luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 16);
|
luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 16);
|
||||||
|
24
src/luajit.c
24
src/luajit.c
@ -71,6 +71,7 @@ static void print_usage(void)
|
|||||||
" -O[opt] Control LuaJIT optimizations.\n"
|
" -O[opt] Control LuaJIT optimizations.\n"
|
||||||
" -i Enter interactive mode after executing " LUA_QL("script") ".\n"
|
" -i Enter interactive mode after executing " LUA_QL("script") ".\n"
|
||||||
" -v Show version information.\n"
|
" -v Show version information.\n"
|
||||||
|
" -E Ignore environment variables.\n"
|
||||||
" -- Stop handling options.\n"
|
" -- Stop handling options.\n"
|
||||||
" - Execute stdin and stop handling options.\n"
|
" - Execute stdin and stop handling options.\n"
|
||||||
,
|
,
|
||||||
@ -406,6 +407,7 @@ static int dobytecode(lua_State *L, char **argv)
|
|||||||
#define FLAGS_VERSION 2
|
#define FLAGS_VERSION 2
|
||||||
#define FLAGS_EXEC 4
|
#define FLAGS_EXEC 4
|
||||||
#define FLAGS_OPTION 8
|
#define FLAGS_OPTION 8
|
||||||
|
#define FLAGS_NOENV 16
|
||||||
|
|
||||||
static int collectargs(char **argv, int *flags)
|
static int collectargs(char **argv, int *flags)
|
||||||
{
|
{
|
||||||
@ -442,6 +444,9 @@ static int collectargs(char **argv, int *flags)
|
|||||||
if (*flags) return -1;
|
if (*flags) return -1;
|
||||||
*flags |= FLAGS_EXEC;
|
*flags |= FLAGS_EXEC;
|
||||||
return 0;
|
return 0;
|
||||||
|
case 'E':
|
||||||
|
*flags |= FLAGS_NOENV;
|
||||||
|
break;
|
||||||
default: return -1; /* invalid option */
|
default: return -1; /* invalid option */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -521,23 +526,30 @@ static int pmain(lua_State *L)
|
|||||||
globalL = L;
|
globalL = L;
|
||||||
if (argv[0] && argv[0][0]) progname = argv[0];
|
if (argv[0] && argv[0][0]) progname = argv[0];
|
||||||
LUAJIT_VERSION_SYM(); /* linker-enforced version check */
|
LUAJIT_VERSION_SYM(); /* linker-enforced version check */
|
||||||
lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */
|
|
||||||
luaL_openlibs(L); /* open libraries */
|
|
||||||
lua_gc(L, LUA_GCRESTART, -1);
|
|
||||||
s->status = handle_luainit(L);
|
|
||||||
if (s->status != 0) return 0;
|
|
||||||
script = collectargs(argv, &flags);
|
script = collectargs(argv, &flags);
|
||||||
if (script < 0) { /* invalid args? */
|
if (script < 0) { /* invalid args? */
|
||||||
print_usage();
|
print_usage();
|
||||||
s->status = 1;
|
s->status = 1;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if ((flags & FLAGS_NOENV)) {
|
||||||
|
lua_pushboolean(L, 1);
|
||||||
|
lua_setfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
|
||||||
|
}
|
||||||
|
lua_gc(L, LUA_GCSTOP, 0); /* stop collector during initialization */
|
||||||
|
luaL_openlibs(L); /* open libraries */
|
||||||
|
lua_gc(L, LUA_GCRESTART, -1);
|
||||||
|
if (!(flags & FLAGS_NOENV)) {
|
||||||
|
s->status = handle_luainit(L);
|
||||||
|
if (s->status != 0) return 0;
|
||||||
|
}
|
||||||
if ((flags & FLAGS_VERSION)) print_version();
|
if ((flags & FLAGS_VERSION)) print_version();
|
||||||
s->status = runargs(L, argv, (script > 0) ? script : s->argc);
|
s->status = runargs(L, argv, (script > 0) ? script : s->argc);
|
||||||
if (s->status != 0) return 0;
|
if (s->status != 0) return 0;
|
||||||
if (script)
|
if (script) {
|
||||||
s->status = handle_script(L, argv, script);
|
s->status = handle_script(L, argv, script);
|
||||||
if (s->status != 0) return 0;
|
if (s->status != 0) return 0;
|
||||||
|
}
|
||||||
if ((flags & FLAGS_INTERACTIVE)) {
|
if ((flags & FLAGS_INTERACTIVE)) {
|
||||||
print_jit_status(L);
|
print_jit_status(L);
|
||||||
dotty(L);
|
dotty(L);
|
||||||
|
Loading…
Reference in New Issue
Block a user