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:
Alex Szpakowski
2014-03-17 20:14:53 -03:00
parent 9e6a3b8d5e
commit aba17607aa
@@ -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++;