summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorShadowNinja <shadowninja@minetest.net>2015-05-04 14:59:13 -0400
committerShadowNinja <shadowninja@minetest.net>2015-05-16 18:33:22 -0400
commit8f9af57314f71aae1cc77e13f9996e13015d776d (patch)
tree6d939e4d54ef864e9463adce51eed14c73d7e61a /src
parent6c06330daf04ed1c390131755b64338ca7d79a7e (diff)
downloadminetest-8f9af57314f71aae1cc77e13f9996e13015d776d.tar.gz
minetest-8f9af57314f71aae1cc77e13f9996e13015d776d.tar.bz2
minetest-8f9af57314f71aae1cc77e13f9996e13015d776d.zip
Add core.get_dir_list
Diffstat (limited to 'src')
-rw-r--r--src/script/lua_api/l_mainmenu.cpp26
-rw-r--r--src/script/lua_api/l_util.cpp25
-rw-r--r--src/script/lua_api/l_util.h3
3 files changed, 28 insertions, 26 deletions
diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp
index b068040db..52410f74f 100644
--- a/src/script/lua_api/l_mainmenu.cpp
+++ b/src/script/lua_api/l_mainmenu.cpp
@@ -754,30 +754,6 @@ int ModApiMainMenu::l_get_texturepath_share(lua_State *L)
}
/******************************************************************************/
-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);
diff --git a/src/script/lua_api/l_util.cpp b/src/script/lua_api/l_util.cpp
index 2bcc114e2..d97db2367 100644
--- a/src/script/lua_api/l_util.cpp
+++ b/src/script/lua_api/l_util.cpp
@@ -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);
}
diff --git a/src/script/lua_api/l_util.h b/src/script/lua_api/l_util.h
index 336173664..e75aa28cb 100644
--- a/src/script/lua_api/l_util.h
+++ b/src/script/lua_api/l_util.h
@@ -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);