From bd21f00f0a1bb23d4503d58a502a796dbe3fd5b4 Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Sun, 11 Dec 2011 16:49:40 +0200 Subject: [PATCH] Add minetest.get_modpath(modname) --- data/mods/default/init.lua | 1 + data/mods/experimental/init.lua | 2 ++ src/mods.h | 5 +++++ src/scriptapi.cpp | 18 ++++++++++++++++++ src/server.cpp | 26 ++++++++++++++++++-------- src/server.h | 6 ++++++ 6 files changed, 50 insertions(+), 8 deletions(-) diff --git a/data/mods/default/init.lua b/data/mods/default/init.lua index 782eba5a5..95d9c19ff 100644 --- a/data/mods/default/init.lua +++ b/data/mods/default/init.lua @@ -110,6 +110,7 @@ -- minetest.chat_send_all(text) -- minetest.chat_send_player(name, text) -- minetest.get_player_privs(name) -> set of privs +-- minetest.get_modpath(modname) -> eg. "/home/user/.minetest/usermods/modname" -- -- stackstring_take_item(stackstring) -> stackstring, item -- stackstring_put_item(stackstring, item) -> stackstring, success diff --git a/data/mods/experimental/init.lua b/data/mods/experimental/init.lua index 6b82b02a2..d180d4778 100644 --- a/data/mods/experimental/init.lua +++ b/data/mods/experimental/init.lua @@ -405,4 +405,6 @@ minetest.register_abm({ end, })--]] +print("experimental modpath="..dump(minetest.get_modpath("experimental"))) +-- END diff --git a/src/mods.h b/src/mods.h index a6beb24f2..e85ec2f4c 100644 --- a/src/mods.h +++ b/src/mods.h @@ -17,6 +17,9 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ +#ifndef MODS_HEADER +#define MODS_HEADER + #include "irrlichttypes.h" #include #include @@ -59,3 +62,5 @@ struct ModSpec core::list getMods(core::list &modspaths) throw(ModError); +#endif + diff --git a/src/scriptapi.cpp b/src/scriptapi.cpp index c759683ed..40ad4d547 100644 --- a/src/scriptapi.cpp +++ b/src/scriptapi.cpp @@ -1334,6 +1334,23 @@ static int l_get_player_privs(lua_State *L) return 1; } +// get_modpath(modname) +static int l_get_modpath(lua_State *L) +{ + const char *modname = luaL_checkstring(L, 1); + // Get server from registry + lua_getfield(L, LUA_REGISTRYINDEX, "minetest_server"); + Server *server = (Server*)lua_touserdata(L, -1); + // Do it + const ModSpec *mod = server->getModSpec(modname); + if(!mod){ + lua_pushnil(L); + return 1; + } + lua_pushstring(L, mod->path.c_str()); + return 1; +} + static const struct luaL_Reg minetest_f [] = { {"register_nodedef_defaults", l_register_nodedef_defaults}, {"register_entity", l_register_entity}, @@ -1350,6 +1367,7 @@ static const struct luaL_Reg minetest_f [] = { {"chat_send_all", l_chat_send_all}, {"chat_send_player", l_chat_send_player}, {"get_player_privs", l_get_player_privs}, + {"get_modpath", l_get_modpath}, {NULL, NULL} }; diff --git a/src/server.cpp b/src/server.cpp index 11c11b259..68a84b248 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -910,10 +910,10 @@ Server::Server( throw ModError("Failed to load and run "+builtinpath); } // Load and run "mod" scripts - core::list mods = getMods(m_modspaths); - for(core::list::Iterator i = mods.begin(); - i != mods.end(); i++){ - ModSpec mod = *i; + m_mods = getMods(m_modspaths); + for(core::list::Iterator i = m_mods.begin(); + i != m_mods.end(); i++){ + const ModSpec &mod = *i; infostream<<"Server: Loading mod \""<()); u32 texture_size_bunch_total = 0; - core::list mods = getMods(m_modspaths); - for(core::list::Iterator i = mods.begin(); - i != mods.end(); i++){ - ModSpec mod = *i; + for(core::list::Iterator i = m_mods.begin(); + i != m_mods.end(); i++){ + const ModSpec &mod = *i; std::string texturepath = mod.path + DIR_DELIM + "textures"; std::vector dirlist = fs::GetDirListing(texturepath); for(u32 j=0; j::Iterator i = m_mods.begin(); + i != m_mods.end(); i++){ + const ModSpec &mod = *i; + if(mod.name == modname) + return &mod; + } + return NULL; +} + v3f findSpawnPos(ServerMap &map) { //return v3f(50,50,50)*BS; diff --git a/src/server.h b/src/server.h index f775f3391..ac8938175 100644 --- a/src/server.h +++ b/src/server.h @@ -32,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "gamedef.h" #include "serialization.h" // For SER_FMT_VER_INVALID #include "serverremoteplayer.h" +#include "mods.h" struct LuaState; typedef struct lua_State lua_State; class IWritableToolDefManager; @@ -502,6 +503,8 @@ public: IWritableCraftDefManager* getWritableCraftDefManager(); IWritableCraftItemDefManager* getWritableCraftItemDefManager(); + const ModSpec* getModSpec(const std::string &modname); + private: // con::PeerHandler implementation. @@ -646,6 +649,9 @@ private: // CraftItem definition manager IWritableCraftItemDefManager *m_craftitemdef; + // Mods + core::list m_mods; + /* Threads */ -- 2.25.1