mirror of
https://github.com/love2d/love.git
synced 2026-08-20 04:30:09 +02:00
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:
@@ -277,6 +277,24 @@ int w_getSourceBaseDirectory(lua_State *L)
|
|||||||
return 1;
|
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)
|
int w_exists(lua_State *L)
|
||||||
{
|
{
|
||||||
const char *arg = luaL_checkstring(L, 1);
|
const char *arg = luaL_checkstring(L, 1);
|
||||||
@@ -658,6 +676,7 @@ static const luaL_Reg functions[] =
|
|||||||
{ "getAppdataDirectory", w_getAppdataDirectory },
|
{ "getAppdataDirectory", w_getAppdataDirectory },
|
||||||
{ "getSaveDirectory", w_getSaveDirectory },
|
{ "getSaveDirectory", w_getSaveDirectory },
|
||||||
{ "getSourceBaseDirectory", w_getSourceBaseDirectory },
|
{ "getSourceBaseDirectory", w_getSourceBaseDirectory },
|
||||||
|
{ "getRealDirectory", w_getRealDirectory },
|
||||||
{ "exists", w_exists },
|
{ "exists", w_exists },
|
||||||
{ "isDirectory", w_isDirectory },
|
{ "isDirectory", w_isDirectory },
|
||||||
{ "isFile", w_isFile },
|
{ "isFile", w_isFile },
|
||||||
|
|||||||
@@ -56,6 +56,7 @@ int w_getUserDirectory(lua_State *L);
|
|||||||
int w_getAppdataDirectory(lua_State *L);
|
int w_getAppdataDirectory(lua_State *L);
|
||||||
int w_getSaveDirectory(lua_State *L);
|
int w_getSaveDirectory(lua_State *L);
|
||||||
int w_getSourceBaseDirectory(lua_State *L);
|
int w_getSourceBaseDirectory(lua_State *L);
|
||||||
|
int w_getRealDirectory(lua_State *L);
|
||||||
int w_exists(lua_State *L);
|
int w_exists(lua_State *L);
|
||||||
int w_isDirectory(lua_State *L);
|
int w_isDirectory(lua_State *L);
|
||||||
int w_isFile(lua_State *L);
|
int w_isFile(lua_State *L);
|
||||||
|
|||||||
Reference in New Issue
Block a user