mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
Added an optional callback function argument to love.filesystem.getDirectoryItems. Callback function takes a single argument containing a filepath string.
For example: love.filesystem.getDirectoryItems("", print)
This commit is contained in:
@@ -477,6 +477,10 @@ void Filesystem::append(const char *filename, const void *data, int64 size) cons
|
||||
int Filesystem::getDirectoryItems(lua_State *L)
|
||||
{
|
||||
const char *dir = luaL_checkstring(L, 1);
|
||||
bool hascallback = !lua_isnoneornil(L, 2);
|
||||
|
||||
if (hascallback)
|
||||
luaL_checktype(L, 2, LUA_TFUNCTION);
|
||||
|
||||
char **rc = PHYSFS_enumerateFiles(dir);
|
||||
int index = 1;
|
||||
@@ -485,6 +489,13 @@ int Filesystem::getDirectoryItems(lua_State *L)
|
||||
|
||||
for (char **i = rc; *i != 0; i++)
|
||||
{
|
||||
if (hascallback)
|
||||
{
|
||||
lua_pushvalue(L, 2);
|
||||
lua_pushstring(L, *i);
|
||||
lua_call(L, 1, 0);
|
||||
}
|
||||
|
||||
lua_pushstring(L, *i);
|
||||
lua_rawseti(L, -2, index);
|
||||
index++;
|
||||
|
||||
Reference in New Issue
Block a user