#define AUXMARK "\1"
static void setpath(lua_State *L, const char *fieldname, const char *envname,
- const char *def)
+ const char *def, int noenv)
{
#if LJ_TARGET_CONSOLE
const char *path = NULL;
#else
const char *path = getenv(envname);
#endif
- if (path == NULL) {
+ if (path == NULL || noenv) {
lua_pushstring(L, def);
} else {
path = luaL_gsub(L, path, LUA_PATHSEP LUA_PATHSEP,
LUALIB_API int luaopen_package(lua_State *L)
{
int i;
+ int noenv;
luaL_newmetatable(L, "_LOADLIB");
lj_lib_pushcf(L, lj_cf_package_unloadlib, 1);
lua_setfield(L, -2, "__gc");
lua_rawseti(L, -2, i+1);
}
lua_setfield(L, -2, "loaders");
- setpath(L, "path", LUA_PATH, LUA_PATH_DEFAULT);
- setpath(L, "cpath", LUA_CPATH, LUA_CPATH_DEFAULT);
+ lua_getfield(L, LUA_REGISTRYINDEX, "LUA_NOENV");
+ 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_setfield(L, -2, "config");
luaL_findtable(L, LUA_REGISTRYINDEX, "_LOADED", 16);
" -O[opt] Control LuaJIT optimizations.\n"
" -i Enter interactive mode after executing " LUA_QL("script") ".\n"
" -v Show version information.\n"
+ " -E Ignore environment variables.\n"
" -- Stop handling options.\n"
" - Execute stdin and stop handling options.\n"
,
#define FLAGS_VERSION 2
#define FLAGS_EXEC 4
#define FLAGS_OPTION 8
+#define FLAGS_NOENV 16
static int collectargs(char **argv, int *flags)
{
if (*flags) return -1;
*flags |= FLAGS_EXEC;
return 0;
+ case 'E':
+ *flags |= FLAGS_NOENV;
+ break;
default: return -1; /* invalid option */
}
}
globalL = L;
if (argv[0] && argv[0][0]) progname = argv[0];
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);
if (script < 0) { /* invalid args? */
print_usage();
s->status = 1;
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();
s->status = runargs(L, argv, (script > 0) ? script : s->argc);
if (s->status != 0) return 0;
- if (script)
+ if (script) {
s->status = handle_script(L, argv, script);
- if (s->status != 0) return 0;
+ if (s->status != 0) return 0;
+ }
if ((flags & FLAGS_INTERACTIVE)) {
print_jit_status(L);
dotty(L);