mirror of
https://github.com/minetest/minetest.git
synced 2024-11-23 08:03:45 +01:00
Introduce get_modpath() for CSM
This commit is contained in:
parent
82a2e02323
commit
b1f2a69382
@ -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")
|
||||
|
@ -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)
|
||||
|
@ -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:
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user