Allow getting the path of builtin.lua using minetest.get_modpath("__builtin")
authorPerttu Ahola <celeron55@gmail.com>
Sun, 1 Apr 2012 07:08:52 +0000 (10:08 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Sun, 1 Apr 2012 09:38:14 +0000 (12:38 +0300)
src/scriptapi.cpp
src/server.cpp
src/server.h

index a86c56f9c98016ec613b3803c8be431c2e284e9a..ac51422096f7b060e80d34c9ee66d483938bcdde 100644 (file)
@@ -3928,8 +3928,13 @@ static int l_get_current_modname(lua_State *L)
 // get_modpath(modname)
 static int l_get_modpath(lua_State *L)
 {
-       const char *modname = luaL_checkstring(L, 1);
+       std::string modname = luaL_checkstring(L, 1);
        // Do it
+       if(modname == "__builtin"){
+               std::string path = get_server(L)->getBuiltinLuaPath();
+               lua_pushstring(L, path.c_str());
+               return 1;
+       }
        const ModSpec *mod = get_server(L)->getModSpec(modname);
        if(!mod){
                lua_pushnil(L);
index b015e103e9cd5791f0275cf6d1c0fa6308d388dd..c06fcb0fd98777869fda7c35ce3defeecf96f92b 100644 (file)
@@ -964,8 +964,7 @@ Server::Server(
        }
        
        // Path to builtin.lua
-       std::string builtinpath = porting::path_share + DIR_DELIM + "builtin"
-                       + DIR_DELIM + "builtin.lua";
+       std::string builtinpath = getBuiltinLuaPath() + DIR_DELIM + "builtin.lua";
 
        // Create world if it doesn't exist
        if(!initializeWorld(m_path_world, m_gamespec.id))
@@ -4410,6 +4409,10 @@ const ModSpec* Server::getModSpec(const std::string &modname)
        }
        return NULL;
 }
+std::string Server::getBuiltinLuaPath()
+{
+       return porting::path_share + DIR_DELIM + "builtin";
+}
 
 v3f findSpawnPos(ServerMap &map)
 {
index abe466b16f957e042810ff0f7d62aa03d4475f69..9cbefa6440295bc87c0d19747cc98637ba892b9c 100644 (file)
@@ -553,6 +553,7 @@ public:
        IWritableCraftDefManager* getWritableCraftDefManager();
 
        const ModSpec* getModSpec(const std::string &modname);
+       std::string getBuiltinLuaPath();
        
        std::string getWorldPath(){ return m_path_world; }