mirror of
https://github.com/love2d/love.git
synced 2026-08-14 01:20:56 +02:00
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:
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user