Add core.get_dir_list
authorShadowNinja <shadowninja@minetest.net>
Mon, 4 May 2015 18:59:13 +0000 (14:59 -0400)
committerShadowNinja <shadowninja@minetest.net>
Sat, 16 May 2015 22:33:22 +0000 (18:33 -0400)
builtin/mainmenu/modmgr.lua
builtin/mainmenu/tab_texturepacks.lua
doc/lua_api.txt
doc/menu_lua_api.txt
src/script/lua_api/l_mainmenu.cpp
src/script/lua_api/l_util.cpp
src/script/lua_api/l_util.h

index f6b9b4814c7cf6ef6e1eb7be59e6cdbf6a15152d..89292ed52e6298a302181365b7bec42a242f7256 100644 (file)
@@ -17,7 +17,7 @@
 
 --------------------------------------------------------------------------------
 function get_mods(path,retval,modpack)
-       local mods = core.get_dirlist(path, true)
+       local mods = core.get_dir_list(path, true)
        
        for i=1, #mods, 1 do
                if mods[i]:sub(1,1) ~= "." then
@@ -94,7 +94,7 @@ function modmgr.getbasefolder(temppath)
                                }
        end
 
-       local subdirs = core.get_dirlist(temppath,true)
+       local subdirs = core.get_dir_list(temppath, true)
 
        --only single mod or modpack allowed
        if #subdirs ~= 1 then
index d32c073ab80aef58c3527566b7476995e5fa5003..9417b94e04cdabe3650e7330efb00ba7c4986207 100644 (file)
@@ -50,7 +50,7 @@ local function get_formspec(tabview, name, tabdata)
                        "textlist[4,0.25;7.5,5.0;TPs;"
 
        local current_texture_path = core.setting_get("texture_path")
-       local list = filter_texture_pack_list(core.get_dirlist(core.get_texturepath(), true))
+       local list = filter_texture_pack_list(core.get_dir_list(core.get_texturepath(), true))
        local index = tonumber(core.setting_get("mainmenu_last_selected_TP"))
 
        if index == nil then index = 1 end
@@ -94,7 +94,7 @@ local function main_button_handler(tabview, fields, name, tabdata)
                        local index = core.get_textlist_index("TPs")
                        core.setting_set("mainmenu_last_selected_TP",
                                index)
-                       local list = filter_texture_pack_list(core.get_dirlist(core.get_texturepath(), true))
+                       local list = filter_texture_pack_list(core.get_dir_list(core.get_texturepath(), true))
                        local current_index = core.get_textlist_index("TPs")
                        if current_index ~= nil and #list >= current_index then
                                local new_path = core.get_texturepath()..DIR_DELIM..list[current_index]
index 0e1dc487f2635cddf75e1f61f5177296cb1755ce..e1ee42b947b96272dd61c061ddec8c00b99ccf50 100644 (file)
@@ -1704,6 +1704,11 @@ Helper functions
 * `minetest.mkdir(path)`: returns success.
     * Creates a directory specified by `path`, creating parent directories
       if they don't exist.
+* `minetest.get_dir_list(path, [is_dir])`: returns list of entry names
+    * is_dir is one of:
+      * nil: return all entries,
+      * true: return only subdirectory names, or
+      * false: return only file names.
 
 ### Logging
 * `minetest.debug(line)`
index e5ba46d4c0998e63eb259c59a757256682d8b262..76c329de69ec9b66ce2d8740bf90baad4127747f 100644 (file)
@@ -31,8 +31,8 @@ core.start()
 core.close()
 
 Filesystem:
-core.get_scriptdir()
-^ returns directory of script
+core.get_builtin_path()
+^ returns path to builtin root
 core.get_modpath() (possible in async calls)
 ^ returns path to global modpath
 core.get_modstore_details(modid) (possible in async calls)
@@ -59,10 +59,6 @@ core.get_gamepath() (possible in async calls)
 ^ returns path to global gamepath
 core.get_texturepath() (possible in async calls)
 ^ returns path to default textures
-core.get_dirlist(path,onlydirs) (possible in async calls)
-^ path to get subdirs from
-^ onlydirs should result contain only dirs?
-^ returns list of folders within path
 core.create_dir(absolute_path) (possible in async calls)
 ^ absolute_path to directory to create (needs to be absolute)
 ^ returns true/false
index b068040db67cdd9452c797002ef73d2ef0369c8c..52410f74f21cace55496f1441e7b128cc3b997c0 100644 (file)
@@ -753,30 +753,6 @@ int ModApiMainMenu::l_get_texturepath_share(lua_State *L)
        return 1;
 }
 
-/******************************************************************************/
-int ModApiMainMenu::l_get_dirlist(lua_State *L)
-{
-       const char *path        = luaL_checkstring(L, 1);
-       bool dironly            = lua_toboolean(L, 2);
-
-       std::vector<fs::DirListNode> dirlist = fs::GetDirListing(path);
-
-       unsigned int index = 1;
-       lua_newtable(L);
-       int table = lua_gettop(L);
-
-       for (unsigned int i=0;i< dirlist.size(); i++) {
-               if ((dirlist[i].dir) || (dironly == false)) {
-                       lua_pushnumber(L,index);
-                       lua_pushstring(L,dirlist[i].name.c_str());
-                       lua_settable(L, table);
-                       index++;
-               }
-       }
-
-       return 1;
-}
-
 /******************************************************************************/
 int ModApiMainMenu::l_create_dir(lua_State *L) {
        const char *path        = luaL_checkstring(L, 1);
@@ -1170,7 +1146,6 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
        API_FCT(get_gamepath);
        API_FCT(get_texturepath);
        API_FCT(get_texturepath_share);
-       API_FCT(get_dirlist);
        API_FCT(create_dir);
        API_FCT(delete_dir);
        API_FCT(copy_dir);
@@ -1204,7 +1179,6 @@ void ModApiMainMenu::InitializeAsync(AsyncEngine& engine)
        ASYNC_API_FCT(get_gamepath);
        ASYNC_API_FCT(get_texturepath);
        ASYNC_API_FCT(get_texturepath_share);
-       ASYNC_API_FCT(get_dirlist);
        ASYNC_API_FCT(create_dir);
        ASYNC_API_FCT(delete_dir);
        ASYNC_API_FCT(copy_dir);
index 2bcc114e289ae87afa70998a46187399aa14d369..d97db23675301e6d03ad0c0a82de78817f5b9176 100644 (file)
@@ -339,6 +339,29 @@ int ModApiUtil::l_mkdir(lua_State *L)
        return 1;
 }
 
+// get_dir_list(path, is_dir)
+int ModApiUtil::l_get_dir_list(lua_State *L)
+{
+       NO_MAP_LOCK_REQUIRED;
+       const char *path = luaL_checkstring(L, 1);
+       short is_dir = lua_isboolean(L, 2) ? lua_toboolean(L, 2) : -1;
+
+       CHECK_SECURE_PATH_OPTIONAL(L, path);
+
+       std::vector<fs::DirListNode> list = fs::GetDirListing(path);
+
+       int index = 0;
+       lua_newtable(L);
+
+       for (size_t i = 0; i < list.size(); i++) {
+               if (is_dir == -1 || is_dir == list[i].dir) {
+                       lua_pushstring(L, list[i].name.c_str());
+                       lua_rawseti(L, -2, ++index);
+               }
+       }
+
+       return 1;
+}
 
 int ModApiUtil::l_request_insecure_environment(lua_State *L)
 {
@@ -391,6 +414,7 @@ void ModApiUtil::Initialize(lua_State *L, int top)
        API_FCT(decompress);
 
        API_FCT(mkdir);
+       API_FCT(get_dir_list);
 
        API_FCT(request_insecure_environment);
 }
@@ -417,5 +441,6 @@ void ModApiUtil::InitializeAsync(AsyncEngine& engine)
        ASYNC_API_FCT(decompress);
 
        ASYNC_API_FCT(mkdir);
+       ASYNC_API_FCT(get_dir_list);
 }
 
index 33617366493105d375e958a916431072d1985cb2..e75aa28cb0ef59f94e6b882810beec2fc197c54f 100644 (file)
@@ -90,6 +90,9 @@ private:
        // mkdir(path)
        static int l_mkdir(lua_State *L);
 
+       // get_dir_list(path, is_dir)
+       static int l_get_dir_list(lua_State *L);
+
        // request_insecure_environment()
        static int l_request_insecure_environment(lua_State *L);