print("Loaded example file!, loading more examples")
-dofile("preview:examples/first.lua")
+dofile(core.get_modpath(core.get_current_modname()) .. "examples/first.lua")
-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)
### 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:
#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)
{
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);
// 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);