Added love.filesystem.getRealDirectory(filepath).

It returns the platform-specific full path of the directory containing the filepath (rather than the file.) For example, if 'saves/save1.txt' exists in the save directory, love.filesystem.getRealDirectory("saves/save1.txt") will equal love.filesystem.getSaveDirectory().
This commit is contained in:
Alex Szpakowski
2015-02-09 17:43:59 -04:00
parent 70ea0e1f3f
commit 320ec8b472
2 changed files with 20 additions and 0 deletions
@@ -277,6 +277,24 @@ int w_getSourceBaseDirectory(lua_State *L)
return 1;
}
int w_getRealDirectory(lua_State *L)
{
const char *filename = luaL_checkstring(L, 1);
std::string dir;
try
{
dir = instance()->getRealDirectory(filename);
}
catch (love::Exception &e)
{
return luax_ioError(L, "%s", e.what());
}
lua_pushstring(L, dir.c_str());
return 1;
}
int w_exists(lua_State *L)
{
const char *arg = luaL_checkstring(L, 1);
@@ -658,6 +676,7 @@ static const luaL_Reg functions[] =
{ "getAppdataDirectory", w_getAppdataDirectory },
{ "getSaveDirectory", w_getSaveDirectory },
{ "getSourceBaseDirectory", w_getSourceBaseDirectory },
{ "getRealDirectory", w_getRealDirectory },
{ "exists", w_exists },
{ "isDirectory", w_isDirectory },
{ "isFile", w_isFile },