- [NEW] sys.dir() ara torna un array de entrades amb nom i si es directori
This commit is contained in:
17
lua.cpp
17
lua.cpp
@@ -720,13 +720,26 @@ extern "C" {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int cpp_sys_dir(lua_State *L) {
|
static int cpp_sys_dir(lua_State *L) {
|
||||||
|
std::string path = "./data";
|
||||||
|
if (lua_gettop(L) > 0) path = luaL_checkstring(L, 1);
|
||||||
|
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
int i=1;
|
int i=1;
|
||||||
for (const auto& entry : fs::directory_iterator("./data")) {
|
|
||||||
|
for (const auto& entry : fs::directory_iterator(path)) {
|
||||||
|
lua_newtable(L); // create subtable for this entry
|
||||||
|
|
||||||
|
// name field
|
||||||
lua_pushstring(L, entry.path().u8string().c_str());
|
lua_pushstring(L, entry.path().u8string().c_str());
|
||||||
|
lua_setfield(L, -2, "name");
|
||||||
|
|
||||||
|
// dir field (true if directory, false otherwise)
|
||||||
|
lua_pushboolean(L, entry.is_directory());
|
||||||
|
lua_setfield(L, -2, "dir");
|
||||||
|
|
||||||
|
// insert subtable into main table at index i
|
||||||
lua_rawseti(L, -2, i++);
|
lua_rawseti(L, -2, i++);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -416,9 +416,16 @@ function sys.beat(bts) end
|
|||||||
function sys.update(mode, ms) end
|
function sys.update(mode, ms) end
|
||||||
|
|
||||||
---@return table
|
---@return table
|
||||||
---Gets a table with the name of each file in the data directory
|
---Gets a table in which each entry has a field "name" with the name and a field "dir" with a
|
||||||
|
---boolean specifying if it's a directory, for each file in the 'data' directory
|
||||||
function sys.dir() end
|
function sys.dir() end
|
||||||
|
|
||||||
|
---@param path string
|
||||||
|
---@return table
|
||||||
|
---Gets a table in which each entry has a field "name" with the name and a field "dir" with a
|
||||||
|
---boolean specifying if it's a directory, for each file in the specified path
|
||||||
|
function sys.dir(path) end
|
||||||
|
|
||||||
---Exit the game
|
---Exit the game
|
||||||
function sys.quit() end
|
function sys.quit() end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user