Skip to content

Commit 9fab5d5

Browse files
authored
Add "MINETEST_MOD_PATH" environment variable (#11515)
This adds an environment variable MINETEST_MOD_PATH. When it exists, Minetest will look there for mods in addition to ~/.minetest/mods/.
1 parent 53e126a commit 9fab5d5

12 files changed

Lines changed: 74 additions & 6 deletions

File tree

builtin/mainmenu/pkgmgr.lua

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -682,11 +682,9 @@ function pkgmgr.preparemodlist(data)
682682
local game_mods = {}
683683

684684
--read global mods
685-
local modpath = core.get_modpath()
686-
687-
if modpath ~= nil and
688-
modpath ~= "" then
689-
get_mods(modpath,global_mods)
685+
local modpaths = core.get_modpaths()
686+
for _, modpath in ipairs(modpaths) do
687+
get_mods(modpath, global_mods)
690688
end
691689

692690
for i=1,#global_mods,1 do

doc/menu_lua_api.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,13 @@ Package - content which is downloadable from the content db, may or may not be i
219219
* returns path to global user data,
220220
the directory that contains user-provided mods, worlds, games, and texture packs.
221221
* core.get_modpath() (possible in async calls)
222-
* returns path to global modpath
222+
* returns path to global modpath, where mods can be installed
223+
* core.get_modpaths() (possible in async calls)
224+
* returns list of paths to global modpaths, where mods have been installed
225+
226+
The difference with "core.get_modpath" is that no mods should be installed in these
227+
directories by Minetest -- they might be read-only.
228+
223229
* core.get_clientmodpath() (possible in async calls)
224230
* returns path to global client-side modpath
225231
* core.get_gamepath() (possible in async calls)

doc/minetest.6

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ Display an interactive terminal over ncurses during execution.
119119
.TP
120120
.B MINETEST_SUBGAME_PATH
121121
Colon delimited list of directories to search for games.
122+
.TP
123+
.B MINETEST_MOD_PATH
124+
Colon delimited list of directories to search for mods.
122125

123126
.SH BUGS
124127
Please report all bugs at https://github.com/minetest/minetest/issues.

src/content/subgames.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ SubgameSpec findSubgame(const std::string &id)
113113
if (user != share || user_game)
114114
mods_paths.insert(user + DIR_DELIM + "mods");
115115

116+
for (const std::string &mod_path : getEnvModPaths()) {
117+
mods_paths.insert(mod_path);
118+
}
119+
116120
// Get meta
117121
std::string conf_path = game_path + DIR_DELIM + "game.conf";
118122
Settings conf;
@@ -384,3 +388,13 @@ void loadGameConfAndInitWorld(const std::string &path, const std::string &name,
384388
if (new_game_settings)
385389
delete game_settings;
386390
}
391+
392+
std::vector<std::string> getEnvModPaths()
393+
{
394+
const char *c_mod_path = getenv("MINETEST_MOD_PATH");
395+
std::vector<std::string> paths;
396+
Strfnd search_paths(c_mod_path ? c_mod_path : "");
397+
while (!search_paths.at_end())
398+
paths.push_back(search_paths.next(PATH_DELIM));
399+
return paths;
400+
}

src/content/subgames.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ SubgameSpec findWorldSubgame(const std::string &world_path);
5858

5959
std::set<std::string> getAvailableGameIds();
6060
std::vector<SubgameSpec> getAvailableGames();
61+
// Get the list of paths to mods in the environment variable $MINETEST_MOD_PATH
62+
std::vector<std::string> getEnvModPaths();
6163

6264
bool getWorldExists(const std::string &world_path);
6365
//! Try to get the displayed name of a world

src/script/lua_api/l_mainmenu.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,21 @@ int ModApiMainMenu::l_get_modpath(lua_State *L)
502502
return 1;
503503
}
504504

505+
/******************************************************************************/
506+
int ModApiMainMenu::l_get_modpaths(lua_State *L)
507+
{
508+
int index = 1;
509+
lua_newtable(L);
510+
ModApiMainMenu::l_get_modpath(L);
511+
lua_rawseti(L, -2, index);
512+
for (const std::string &component : getEnvModPaths()) {
513+
index++;
514+
lua_pushstring(L, component.c_str());
515+
lua_rawseti(L, -2, index);
516+
}
517+
return 1;
518+
}
519+
505520
/******************************************************************************/
506521
int ModApiMainMenu::l_get_clientmodpath(lua_State *L)
507522
{
@@ -856,6 +871,7 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
856871
API_FCT(get_mapgen_names);
857872
API_FCT(get_user_path);
858873
API_FCT(get_modpath);
874+
API_FCT(get_modpaths);
859875
API_FCT(get_clientmodpath);
860876
API_FCT(get_gamepath);
861877
API_FCT(get_texturepath);
@@ -889,6 +905,7 @@ void ModApiMainMenu::InitializeAsync(lua_State *L, int top)
889905
API_FCT(get_mapgen_names);
890906
API_FCT(get_user_path);
891907
API_FCT(get_modpath);
908+
API_FCT(get_modpaths);
892909
API_FCT(get_clientmodpath);
893910
API_FCT(get_gamepath);
894911
API_FCT(get_texturepath);

src/script/lua_api/l_mainmenu.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ class ModApiMainMenu: public ModApiBase
112112

113113
static int l_get_modpath(lua_State *L);
114114

115+
static int l_get_modpaths(lua_State *L);
116+
115117
static int l_get_clientmodpath(lua_State *L);
116118

117119
static int l_get_gamepath(lua_State *L);

src/unittest/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ set (UNITTEST_CLIENT_SRCS
4444

4545
set (TEST_WORLDDIR ${CMAKE_CURRENT_SOURCE_DIR}/test_world)
4646
set (TEST_SUBGAME_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../games/devtest)
47+
set (TEST_MOD_PATH ${CMAKE_CURRENT_SOURCE_DIR}/test_mod)
4748

4849
configure_file(
4950
"${CMAKE_CURRENT_SOURCE_DIR}/test_config.h.in"

src/unittest/test_config.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44

55
#define TEST_WORLDDIR "@TEST_WORLDDIR@"
66
#define TEST_SUBGAME_PATH "@TEST_SUBGAME_PATH@"
7+
#define TEST_MOD_PATH "@TEST_MOD_PATH@"
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-- deliberately empty

0 commit comments

Comments
 (0)