forked from Mirrorlandia_minetest/minetest
Add minetest.get_modpath(modname)
This commit is contained in:
parent
012bcbcb48
commit
bd21f00f0a
@ -110,6 +110,7 @@
|
|||||||
-- minetest.chat_send_all(text)
|
-- minetest.chat_send_all(text)
|
||||||
-- minetest.chat_send_player(name, text)
|
-- minetest.chat_send_player(name, text)
|
||||||
-- minetest.get_player_privs(name) -> set of privs
|
-- 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_take_item(stackstring) -> stackstring, item
|
||||||
-- stackstring_put_item(stackstring, item) -> stackstring, success
|
-- stackstring_put_item(stackstring, item) -> stackstring, success
|
||||||
|
@ -405,4 +405,6 @@ minetest.register_abm({
|
|||||||
end,
|
end,
|
||||||
})--]]
|
})--]]
|
||||||
|
|
||||||
|
print("experimental modpath="..dump(minetest.get_modpath("experimental")))
|
||||||
|
|
||||||
|
-- END
|
||||||
|
@ -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.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef MODS_HEADER
|
||||||
|
#define MODS_HEADER
|
||||||
|
|
||||||
#include "irrlichttypes.h"
|
#include "irrlichttypes.h"
|
||||||
#include <set>
|
#include <set>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -59,3 +62,5 @@ struct ModSpec
|
|||||||
core::list<ModSpec> getMods(core::list<std::string> &modspaths)
|
core::list<ModSpec> getMods(core::list<std::string> &modspaths)
|
||||||
throw(ModError);
|
throw(ModError);
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
|
@ -1334,6 +1334,23 @@ static int l_get_player_privs(lua_State *L)
|
|||||||
return 1;
|
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 [] = {
|
static const struct luaL_Reg minetest_f [] = {
|
||||||
{"register_nodedef_defaults", l_register_nodedef_defaults},
|
{"register_nodedef_defaults", l_register_nodedef_defaults},
|
||||||
{"register_entity", l_register_entity},
|
{"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_all", l_chat_send_all},
|
||||||
{"chat_send_player", l_chat_send_player},
|
{"chat_send_player", l_chat_send_player},
|
||||||
{"get_player_privs", l_get_player_privs},
|
{"get_player_privs", l_get_player_privs},
|
||||||
|
{"get_modpath", l_get_modpath},
|
||||||
{NULL, NULL}
|
{NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -910,10 +910,10 @@ Server::Server(
|
|||||||
throw ModError("Failed to load and run "+builtinpath);
|
throw ModError("Failed to load and run "+builtinpath);
|
||||||
}
|
}
|
||||||
// Load and run "mod" scripts
|
// Load and run "mod" scripts
|
||||||
core::list<ModSpec> mods = getMods(m_modspaths);
|
m_mods = getMods(m_modspaths);
|
||||||
for(core::list<ModSpec>::Iterator i = mods.begin();
|
for(core::list<ModSpec>::Iterator i = m_mods.begin();
|
||||||
i != mods.end(); i++){
|
i != m_mods.end(); i++){
|
||||||
ModSpec mod = *i;
|
const ModSpec &mod = *i;
|
||||||
infostream<<"Server: Loading mod \""<<mod.name<<"\""<<std::endl;
|
infostream<<"Server: Loading mod \""<<mod.name<<"\""<<std::endl;
|
||||||
std::string scriptpath = mod.path + DIR_DELIM + "init.lua";
|
std::string scriptpath = mod.path + DIR_DELIM + "init.lua";
|
||||||
bool success = scriptapi_loadmod(m_lua, scriptpath, mod.name);
|
bool success = scriptapi_loadmod(m_lua, scriptpath, mod.name);
|
||||||
@ -4203,10 +4203,9 @@ void Server::SendTextures(u16 peer_id)
|
|||||||
texture_bunches.push_back(core::list<SendableTexture>());
|
texture_bunches.push_back(core::list<SendableTexture>());
|
||||||
|
|
||||||
u32 texture_size_bunch_total = 0;
|
u32 texture_size_bunch_total = 0;
|
||||||
core::list<ModSpec> mods = getMods(m_modspaths);
|
for(core::list<ModSpec>::Iterator i = m_mods.begin();
|
||||||
for(core::list<ModSpec>::Iterator i = mods.begin();
|
i != m_mods.end(); i++){
|
||||||
i != mods.end(); i++){
|
const ModSpec &mod = *i;
|
||||||
ModSpec mod = *i;
|
|
||||||
std::string texturepath = mod.path + DIR_DELIM + "textures";
|
std::string texturepath = mod.path + DIR_DELIM + "textures";
|
||||||
std::vector<fs::DirListNode> dirlist = fs::GetDirListing(texturepath);
|
std::vector<fs::DirListNode> dirlist = fs::GetDirListing(texturepath);
|
||||||
for(u32 j=0; j<dirlist.size(); j++){
|
for(u32 j=0; j<dirlist.size(); j++){
|
||||||
@ -4560,6 +4559,17 @@ IWritableCraftItemDefManager* Server::getWritableCraftItemDefManager()
|
|||||||
return m_craftitemdef;
|
return m_craftitemdef;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const ModSpec* Server::getModSpec(const std::string &modname)
|
||||||
|
{
|
||||||
|
for(core::list<ModSpec>::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)
|
v3f findSpawnPos(ServerMap &map)
|
||||||
{
|
{
|
||||||
//return v3f(50,50,50)*BS;
|
//return v3f(50,50,50)*BS;
|
||||||
|
@ -32,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "gamedef.h"
|
#include "gamedef.h"
|
||||||
#include "serialization.h" // For SER_FMT_VER_INVALID
|
#include "serialization.h" // For SER_FMT_VER_INVALID
|
||||||
#include "serverremoteplayer.h"
|
#include "serverremoteplayer.h"
|
||||||
|
#include "mods.h"
|
||||||
struct LuaState;
|
struct LuaState;
|
||||||
typedef struct lua_State lua_State;
|
typedef struct lua_State lua_State;
|
||||||
class IWritableToolDefManager;
|
class IWritableToolDefManager;
|
||||||
@ -502,6 +503,8 @@ public:
|
|||||||
IWritableCraftDefManager* getWritableCraftDefManager();
|
IWritableCraftDefManager* getWritableCraftDefManager();
|
||||||
IWritableCraftItemDefManager* getWritableCraftItemDefManager();
|
IWritableCraftItemDefManager* getWritableCraftItemDefManager();
|
||||||
|
|
||||||
|
const ModSpec* getModSpec(const std::string &modname);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
// con::PeerHandler implementation.
|
// con::PeerHandler implementation.
|
||||||
@ -646,6 +649,9 @@ private:
|
|||||||
// CraftItem definition manager
|
// CraftItem definition manager
|
||||||
IWritableCraftItemDefManager *m_craftitemdef;
|
IWritableCraftItemDefManager *m_craftitemdef;
|
||||||
|
|
||||||
|
// Mods
|
||||||
|
core::list<ModSpec> m_mods;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Threads
|
Threads
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user