Commits

Alex Szpakowski  committed b97372f

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)

  • Participants
  • Parent commits f5b196c

Comments (0)

Files changed (1)

File src/modules/filesystem/physfs/Filesystem.cpp

 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;
 
 	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++;