diff --git a/changes.txt b/changes.txt index 135f2cf66..2f62dcc1c 100644 --- a/changes.txt +++ b/changes.txt @@ -93,7 +93,7 @@ Released: N/A * Renamed all get[Object]List functions to get[Object]s. * Removed the default source type for love.audio.newSource. - * Removed variant of love.filesystem.newFileData which takes base64 data, use love.math.decode instead. + * Removed variant of love.filesystem.newFileData which takes base64 data, use love.data.decode instead. * Removed the no-argument variant of Text:set, use Text:clear instead. * Removed love.graphics.getCompressedImageFormats, use love.graphics.getImageFormats instead. * Removed the 'void effects(...)' pixel shader entry point. Use the new 'void effect()' instead. diff --git a/src/modules/filesystem/Filesystem.cpp b/src/modules/filesystem/Filesystem.cpp index 48b497dbe..09d002165 100644 --- a/src/modules/filesystem/Filesystem.cpp +++ b/src/modules/filesystem/Filesystem.cpp @@ -130,6 +130,11 @@ bool Filesystem::getConstant(FileType in, const char *&out) return fileTypes.find(in, out); } +std::vector Filesystem::getConstants(FileType) +{ + return fileTypes.getNames(); +} + StringMap::Entry Filesystem::fileTypeEntries[] = { { "file", FILETYPE_FILE }, diff --git a/src/modules/filesystem/Filesystem.h b/src/modules/filesystem/Filesystem.h index a5b9d0874..bd357dd70 100644 --- a/src/modules/filesystem/Filesystem.h +++ b/src/modules/filesystem/Filesystem.h @@ -265,6 +265,7 @@ public: static bool getConstant(const char *in, FileType &out); static bool getConstant(FileType in, const char *&out); + static std::vector getConstants(FileType); private: diff --git a/src/modules/filesystem/wrap_Filesystem.cpp b/src/modules/filesystem/wrap_Filesystem.cpp index cf7071343..9f521d5fd 100644 --- a/src/modules/filesystem/wrap_Filesystem.cpp +++ b/src/modules/filesystem/wrap_Filesystem.cpp @@ -395,14 +395,31 @@ int w_getInfo(lua_State *L) const char *filepath = luaL_checkstring(L, 1); Filesystem::Info info = {}; + int startidx = 2; + Filesystem::FileType filtertype = Filesystem::FILETYPE_MAX_ENUM; + if (lua_isstring(L, startidx)) + { + const char *typestr = luaL_checkstring(L, startidx); + if (!Filesystem::getConstant(typestr, filtertype)) + return luax_enumerror(L, "file type", Filesystem::getConstants(filtertype), typestr); + + startidx++; + } + if (instance()->getInfo(filepath, info)) { + if (filtertype != Filesystem::FILETYPE_MAX_ENUM && info.type != filtertype) + { + lua_pushnil(L); + return 1; + } + const char *typestr = nullptr; if (!Filesystem::getConstant(info.type, typestr)) return luaL_error(L, "Unknown file type."); - if (lua_istable(L, 2)) - lua_pushvalue(L, 2); + if (lua_istable(L, startidx)) + lua_pushvalue(L, startidx); else lua_createtable(L, 0, 3);