1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Add world-independent storage directory for mods (#12315)

Fixes #4821
This commit is contained in:
rubenwardy 2024-03-24 17:18:58 +00:00 committed by GitHub
parent b42b03bc40
commit 6c4a110679
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 44 additions and 0 deletions

View file

@ -29,6 +29,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "environment.h"
#include "remoteplayer.h"
#include "log.h"
#include "filesys.h"
#include <algorithm>
// request_shutdown()
@ -507,6 +508,24 @@ int ModApiServer::l_get_worldpath(lua_State *L)
return 1;
}
// get_mod_data_path()
int ModApiServer::l_get_mod_data_path(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
std::string modname = ScriptApiBase::getCurrentModNameInsecure(L);
if (modname.empty())
return 0;
const Server *srv = getServer(L);
std::string path = srv->getModDataPath() + DIR_DELIM + modname;
if (!fs::CreateAllDirs(path))
throw LuaError("Failed to create dir");
lua_pushstring(L, path.c_str());
return 1;
}
// sound_play(spec, parameters, [ephemeral])
int ModApiServer::l_sound_play(lua_State *L)
{
@ -716,6 +735,7 @@ void ModApiServer::Initialize(lua_State *L, int top)
API_FCT(get_server_status);
API_FCT(get_server_uptime);
API_FCT(get_server_max_lag);
API_FCT(get_mod_data_path);
API_FCT(get_worldpath);
API_FCT(is_singleplayer);

View file

@ -39,6 +39,9 @@ private:
// get_worldpath()
static int l_get_worldpath(lua_State *L);
// get_mod_data_path()
static int l_get_mod_data_path(lua_State *L);
// is_singleplayer()
static int l_is_singleplayer(lua_State *L);