aboutsummaryrefslogtreecommitdiff
path: root/src/lib_package.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib_package.c')
-rw-r--r--src/lib_package.c12
1 files changed, 8 insertions, 4 deletions
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);