]> git.lizzy.rs Git - dragonfireclient.git/commitdiff
Introduce get_modpath() for CSM
authorsfan5 <sfan5@live.de>
Fri, 8 Nov 2019 19:18:41 +0000 (20:18 +0100)
committersfan5 <sfan5@live.de>
Sat, 9 Nov 2019 15:08:38 +0000 (16:08 +0100)
clientmods/preview/example.lua
clientmods/preview/init.lua
doc/client_lua_api.txt
src/script/lua_api/l_client.cpp
src/script/lua_api/l_client.h

index 2f661c073bcf8718c15f16a6b840a2b3be27af16..41dc3b2847238059877840213903da451d925054 100644 (file)
@@ -1,2 +1,2 @@
 print("Loaded example file!, loading more examples")
-dofile("preview:examples/first.lua")
+dofile(core.get_modpath(core.get_current_modname()) .. "examples/first.lua")
index bb8d1d600c5d8595d341fe482dc1899d9b1ef7ba..95cf9ce64bb39e8b3c70fdd57c5016562ae9fb87 100644 (file)
@@ -1,9 +1,9 @@
-local modname = core.get_current_modname() or "??"
+local modname = assert(core.get_current_modname())
 local modstorage = core.get_mod_storage()
 local mod_channel
 
-dofile("preview:example.lua")
--- This is an example function to ensure it's working properly, should be removed before merge
+dofile(core.get_modpath(modname) .. "example.lua")
+
 core.register_on_shutdown(function()
        print("[PREVIEW] shutdown client")
 end)
index d355376f594a446f4d932e4d1e07d0282fed6683..ab7963029a2c6fb005f3dbf8de8987fefaa125fd 100644 (file)
@@ -631,6 +631,10 @@ Minetest namespace reference
 ### Utilities
 
 * `minetest.get_current_modname()`: returns the currently loading mod's name, when we are loading a mod
+* `minetest.get_modpath(modname)`: returns virtual path of given mod including
+   the trailing separator. This is useful to load additional Lua files
+   contained in your mod:
+   e.g. `dofile(minetest.get_modpath(minetest.get_current_modname()) .. "stuff.lua")`
 * `minetest.get_language()`: returns the currently set gettext language.
 * `minetest.get_version()`: returns a table containing components of the
    engine version.  Components:
index 6345fc75f7a7b1ab87671fcfcb00e371caf855f9..febf528de55ce12e582a5b3937dab892305a588b 100644 (file)
@@ -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<std::string>(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);
index 0d3e6b1069efb1defc656af1686bedccccdeaa53..0a68eeff0b6efa0a420429799c71648c177d72fe 100644 (file)
@@ -30,6 +30,9 @@ class ModApiClient : public ModApiBase
        // 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);