Add a variant of love.filesystem.getInfo which filters based on file type. getInfo(filename, "directory") will only return info for non-symlinked directories, for example.

This commit is contained in:
Alex Szpakowski
2018-03-24 14:43:56 -03:00
parent 5bdffa72eb
commit 0cefb12c13
4 changed files with 26 additions and 3 deletions
+19 -2
View File
@@ -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);