From b1f2a693820537c6ecd47b84056da136e2f9f563 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 8 Nov 2019 20:18:41 +0100 Subject: Introduce get_modpath() for CSM --- src/script/lua_api/l_client.cpp | 12 ++++++++++++ src/script/lua_api/l_client.h | 3 +++ 2 files changed, 15 insertions(+) (limited to 'src/script') diff --git a/src/script/lua_api/l_client.cpp b/src/script/lua_api/l_client.cpp index 6345fc75f..febf528de 100644 --- a/src/script/lua_api/l_client.cpp +++ b/src/script/lua_api/l_client.cpp @@ -36,12 +36,23 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "util/string.h" #include "nodedef.h" +// get_current_modname() int ModApiClient::l_get_current_modname(lua_State *L) { lua_rawgeti(L, LUA_REGISTRYINDEX, CUSTOM_RIDX_CURRENT_MOD_NAME); return 1; } +// get_modpath(modname) +int ModApiClient::l_get_modpath(lua_State *L) +{ + std::string modname = readParam(L, 1); + // Client mods use a virtual filesystem, see Client::scanModSubfolder() + std::string path = modname + ":"; + lua_pushstring(L, path.c_str()); + return 1; +} + // get_last_run_mod() int ModApiClient::l_get_last_run_mod(lua_State *L) { @@ -365,6 +376,7 @@ int ModApiClient::l_get_builtin_path(lua_State *L) void ModApiClient::Initialize(lua_State *L, int top) { API_FCT(get_current_modname); + API_FCT(get_modpath); API_FCT(print); API_FCT(display_chat_message); API_FCT(send_chat_message); diff --git a/src/script/lua_api/l_client.h b/src/script/lua_api/l_client.h index 0d3e6b106..0a68eeff0 100644 --- a/src/script/lua_api/l_client.h +++ b/src/script/lua_api/l_client.h @@ -30,6 +30,9 @@ private: // get_current_modname() static int l_get_current_modname(lua_State *L); + // get_modpath(modname) + static int l_get_modpath(lua_State *L); + // print(text) static int l_print(lua_State *L); -- cgit v1.2.3