Skip to content

Commit 8f9af57

Browse files
committedMay 16, 2015
Add core.get_dir_list
1 parent 6c06330 commit 8f9af57

File tree

7 files changed

+39
-36
lines changed

7 files changed

+39
-36
lines changed
 

‎builtin/mainmenu/modmgr.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
--------------------------------------------------------------------------------
1919
function get_mods(path,retval,modpack)
20-
local mods = core.get_dirlist(path, true)
20+
local mods = core.get_dir_list(path, true)
2121

2222
for i=1, #mods, 1 do
2323
if mods[i]:sub(1,1) ~= "." then
@@ -94,7 +94,7 @@ function modmgr.getbasefolder(temppath)
9494
}
9595
end
9696

97-
local subdirs = core.get_dirlist(temppath,true)
97+
local subdirs = core.get_dir_list(temppath, true)
9898

9999
--only single mod or modpack allowed
100100
if #subdirs ~= 1 then

‎builtin/mainmenu/tab_texturepacks.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ local function get_formspec(tabview, name, tabdata)
5050
"textlist[4,0.25;7.5,5.0;TPs;"
5151

5252
local current_texture_path = core.setting_get("texture_path")
53-
local list = filter_texture_pack_list(core.get_dirlist(core.get_texturepath(), true))
53+
local list = filter_texture_pack_list(core.get_dir_list(core.get_texturepath(), true))
5454
local index = tonumber(core.setting_get("mainmenu_last_selected_TP"))
5555

5656
if index == nil then index = 1 end
@@ -94,7 +94,7 @@ local function main_button_handler(tabview, fields, name, tabdata)
9494
local index = core.get_textlist_index("TPs")
9595
core.setting_set("mainmenu_last_selected_TP",
9696
index)
97-
local list = filter_texture_pack_list(core.get_dirlist(core.get_texturepath(), true))
97+
local list = filter_texture_pack_list(core.get_dir_list(core.get_texturepath(), true))
9898
local current_index = core.get_textlist_index("TPs")
9999
if current_index ~= nil and #list >= current_index then
100100
local new_path = core.get_texturepath()..DIR_DELIM..list[current_index]

‎doc/lua_api.txt

+5
Original file line numberDiff line numberDiff line change
@@ -1704,6 +1704,11 @@ Helper functions
17041704
* `minetest.mkdir(path)`: returns success.
17051705
* Creates a directory specified by `path`, creating parent directories
17061706
if they don't exist.
1707+
* `minetest.get_dir_list(path, [is_dir])`: returns list of entry names
1708+
* is_dir is one of:
1709+
* nil: return all entries,
1710+
* true: return only subdirectory names, or
1711+
* false: return only file names.
17071712

17081713
### Logging
17091714
* `minetest.debug(line)`

‎doc/menu_lua_api.txt

+2-6
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ core.start()
3131
core.close()
3232

3333
Filesystem:
34-
core.get_scriptdir()
35-
^ returns directory of script
34+
core.get_builtin_path()
35+
^ returns path to builtin root
3636
core.get_modpath() (possible in async calls)
3737
^ returns path to global modpath
3838
core.get_modstore_details(modid) (possible in async calls)
@@ -59,10 +59,6 @@ core.get_gamepath() (possible in async calls)
5959
^ returns path to global gamepath
6060
core.get_texturepath() (possible in async calls)
6161
^ returns path to default textures
62-
core.get_dirlist(path,onlydirs) (possible in async calls)
63-
^ path to get subdirs from
64-
^ onlydirs should result contain only dirs?
65-
^ returns list of folders within path
6662
core.create_dir(absolute_path) (possible in async calls)
6763
^ absolute_path to directory to create (needs to be absolute)
6864
^ returns true/false

‎src/script/lua_api/l_mainmenu.cpp

-26
Original file line numberDiff line numberDiff line change
@@ -753,30 +753,6 @@ int ModApiMainMenu::l_get_texturepath_share(lua_State *L)
753753
return 1;
754754
}
755755

756-
/******************************************************************************/
757-
int ModApiMainMenu::l_get_dirlist(lua_State *L)
758-
{
759-
const char *path = luaL_checkstring(L, 1);
760-
bool dironly = lua_toboolean(L, 2);
761-
762-
std::vector<fs::DirListNode> dirlist = fs::GetDirListing(path);
763-
764-
unsigned int index = 1;
765-
lua_newtable(L);
766-
int table = lua_gettop(L);
767-
768-
for (unsigned int i=0;i< dirlist.size(); i++) {
769-
if ((dirlist[i].dir) || (dironly == false)) {
770-
lua_pushnumber(L,index);
771-
lua_pushstring(L,dirlist[i].name.c_str());
772-
lua_settable(L, table);
773-
index++;
774-
}
775-
}
776-
777-
return 1;
778-
}
779-
780756
/******************************************************************************/
781757
int ModApiMainMenu::l_create_dir(lua_State *L) {
782758
const char *path = luaL_checkstring(L, 1);
@@ -1170,7 +1146,6 @@ void ModApiMainMenu::Initialize(lua_State *L, int top)
11701146
API_FCT(get_gamepath);
11711147
API_FCT(get_texturepath);
11721148
API_FCT(get_texturepath_share);
1173-
API_FCT(get_dirlist);
11741149
API_FCT(create_dir);
11751150
API_FCT(delete_dir);
11761151
API_FCT(copy_dir);
@@ -1204,7 +1179,6 @@ void ModApiMainMenu::InitializeAsync(AsyncEngine& engine)
12041179
ASYNC_API_FCT(get_gamepath);
12051180
ASYNC_API_FCT(get_texturepath);
12061181
ASYNC_API_FCT(get_texturepath_share);
1207-
ASYNC_API_FCT(get_dirlist);
12081182
ASYNC_API_FCT(create_dir);
12091183
ASYNC_API_FCT(delete_dir);
12101184
ASYNC_API_FCT(copy_dir);

‎src/script/lua_api/l_util.cpp

+25
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,29 @@ int ModApiUtil::l_mkdir(lua_State *L)
339339
return 1;
340340
}
341341

342+
// get_dir_list(path, is_dir)
343+
int ModApiUtil::l_get_dir_list(lua_State *L)
344+
{
345+
NO_MAP_LOCK_REQUIRED;
346+
const char *path = luaL_checkstring(L, 1);
347+
short is_dir = lua_isboolean(L, 2) ? lua_toboolean(L, 2) : -1;
348+
349+
CHECK_SECURE_PATH_OPTIONAL(L, path);
350+
351+
std::vector<fs::DirListNode> list = fs::GetDirListing(path);
352+
353+
int index = 0;
354+
lua_newtable(L);
355+
356+
for (size_t i = 0; i < list.size(); i++) {
357+
if (is_dir == -1 || is_dir == list[i].dir) {
358+
lua_pushstring(L, list[i].name.c_str());
359+
lua_rawseti(L, -2, ++index);
360+
}
361+
}
362+
363+
return 1;
364+
}
342365

343366
int ModApiUtil::l_request_insecure_environment(lua_State *L)
344367
{
@@ -391,6 +414,7 @@ void ModApiUtil::Initialize(lua_State *L, int top)
391414
API_FCT(decompress);
392415

393416
API_FCT(mkdir);
417+
API_FCT(get_dir_list);
394418

395419
API_FCT(request_insecure_environment);
396420
}
@@ -417,5 +441,6 @@ void ModApiUtil::InitializeAsync(AsyncEngine& engine)
417441
ASYNC_API_FCT(decompress);
418442

419443
ASYNC_API_FCT(mkdir);
444+
ASYNC_API_FCT(get_dir_list);
420445
}
421446

‎src/script/lua_api/l_util.h

+3
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ class ModApiUtil : public ModApiBase {
9090
// mkdir(path)
9191
static int l_mkdir(lua_State *L);
9292

93+
// get_dir_list(path, is_dir)
94+
static int l_get_dir_list(lua_State *L);
95+
9396
// request_insecure_environment()
9497
static int l_request_insecure_environment(lua_State *L);
9598

0 commit comments

Comments
 (0)
Please sign in to comment.