From 320ec8b4726ab689342fe8d1fcc9025270626cc5 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Mon, 9 Feb 2015 17:43:59 -0400 Subject: [PATCH] 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(). --- src/modules/filesystem/wrap_Filesystem.cpp | 19 +++++++++++++++++++ src/modules/filesystem/wrap_Filesystem.h | 1 + 2 files changed, 20 insertions(+) diff --git a/src/modules/filesystem/wrap_Filesystem.cpp b/src/modules/filesystem/wrap_Filesystem.cpp index 59af698cd..29138e610 100644 --- a/src/modules/filesystem/wrap_Filesystem.cpp +++ b/src/modules/filesystem/wrap_Filesystem.cpp @@ -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 }, diff --git a/src/modules/filesystem/wrap_Filesystem.h b/src/modules/filesystem/wrap_Filesystem.h index 4c6f3953e..01c952523 100644 --- a/src/modules/filesystem/wrap_Filesystem.h +++ b/src/modules/filesystem/wrap_Filesystem.h @@ -56,6 +56,7 @@ int w_getUserDirectory(lua_State *L); int w_getAppdataDirectory(lua_State *L); int w_getSaveDirectory(lua_State *L); int w_getSourceBaseDirectory(lua_State *L); +int w_getRealDirectory(lua_State *L); int w_exists(lua_State *L); int w_isDirectory(lua_State *L); int w_isFile(lua_State *L);