Add minetest.get_worldpath() for getting location for custom data
authorPerttu Ahola <celeron55@gmail.com>
Tue, 28 Feb 2012 18:41:26 +0000 (20:41 +0200)
committerPerttu Ahola <celeron55@gmail.com>
Tue, 28 Feb 2012 18:41:26 +0000 (20:41 +0200)
data/mods/default/init.lua
data/mods/experimental/init.lua
src/scriptapi.cpp
src/server.h

index d07337379c5e894c5f236898576988ba2ca28e50..3f4a8175eaa94e3b27e10ae15872415376c29129 100644 (file)
 --                  {type="node", pos={x=, y=, z=}}
 -- minetest.get_current_modname() -> string
 -- minetest.get_modpath(modname) -> eg. "/home/user/.minetest/usermods/modname"
+-- ^ Useful for loading additional .lua modules or static data from mod
+-- minetest.get_worldpath(modname) -> eg. "/home/user/.minetest/world"
+-- ^ Useful for storing custom data
 --
 -- minetest.debug(line)
 -- ^ Goes to dstream
index 9a8f8868d5ff31c049126d16ebd0346a56bd47ff..ddc89f92c713f171299b20e2133451deab0b0587 100644 (file)
@@ -540,5 +540,6 @@ minetest.register_abm({
 
 print("experimental modname="..dump(minetest.get_current_modname()))
 print("experimental modpath="..dump(minetest.get_modpath("experimental")))
+print("experimental worldpath="..dump(minetest.get_worldpath()))
 
 -- END
index a064cd688a0b318cdac5c92fb5263c3389a333d6..8350c75f19b63aa1480f901cb1cbd1745db00db8 100644 (file)
@@ -3560,6 +3560,14 @@ static int l_get_modpath(lua_State *L)
        return 1;
 }
 
+// get_worldpath()
+static int l_get_worldpath(lua_State *L)
+{
+       std::string worldpath = get_server(L)->getWorldPath();
+       lua_pushstring(L, worldpath.c_str());
+       return 1;
+}
+
 static const struct luaL_Reg minetest_f [] = {
        {"debug", l_debug},
        {"log", l_log},
@@ -3576,6 +3584,7 @@ static const struct luaL_Reg minetest_f [] = {
        {"get_hitting_properties", l_get_hitting_properties},
        {"get_current_modname", l_get_current_modname},
        {"get_modpath", l_get_modpath},
+       {"get_worldpath", l_get_worldpath},
        {NULL, NULL}
 };
 
index 40f0fe582a49a1b525a507d10ed990d3146dea50..04bd61a87a51f7f65c3473e040825f4a67d05b66 100644 (file)
@@ -525,6 +525,8 @@ public:
        IWritableCraftDefManager* getWritableCraftDefManager();
 
        const ModSpec* getModSpec(const std::string &modname);
+       
+       std::string getWorldPath(){ return m_mapsavedir; }
 
 private: