From 186bcae7cb476ad75f0d8b78962b42ff70ee9a19 Mon Sep 17 00:00:00 2001 From: Alex Szpakowski Date: Thu, 27 Jun 2013 02:23:56 -0300 Subject: [PATCH] Added File:isOpen --- src/modules/filesystem/File.h | 7 ++++++- src/modules/filesystem/physfs/File.cpp | 7 ++++++- src/modules/filesystem/physfs/File.h | 3 ++- src/modules/filesystem/physfs/wrap_File.cpp | 10 +++++++++- src/modules/filesystem/physfs/wrap_File.h | 1 + 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/modules/filesystem/File.h b/src/modules/filesystem/File.h index 1c4d66d2a..dacf3edd4 100644 --- a/src/modules/filesystem/File.h +++ b/src/modules/filesystem/File.h @@ -81,6 +81,11 @@ public: **/ virtual bool close() = 0; + /** + * Gets whether the file is open. + **/ + virtual bool isOpen() const = 0; + /** * Gets the size of the file. * @@ -149,7 +154,7 @@ public: * Gets the current mode of the File. * @return The current mode of the File; CLOSED, READ, WRITE or APPEND. **/ - virtual Mode getMode() = 0; + virtual Mode getMode() const = 0; /** * Gets the filename for this File, or empty string if none. diff --git a/src/modules/filesystem/physfs/File.cpp b/src/modules/filesystem/physfs/File.cpp index 0ab8e8d82..08f1f1aa4 100644 --- a/src/modules/filesystem/physfs/File.cpp +++ b/src/modules/filesystem/physfs/File.cpp @@ -95,6 +95,11 @@ bool File::close() return true; } +bool File::isOpen() const +{ + return mode != CLOSED && file != 0; +} + int64 File::getSize() { // If the file is closed, open it to @@ -249,7 +254,7 @@ std::string File::getExtension() const return std::string(); } -filesystem::File::Mode File::getMode() +filesystem::File::Mode File::getMode() const { return mode; } diff --git a/src/modules/filesystem/physfs/File.h b/src/modules/filesystem/physfs/File.h index f4a0f6d1c..084fce02d 100644 --- a/src/modules/filesystem/physfs/File.h +++ b/src/modules/filesystem/physfs/File.h @@ -68,6 +68,7 @@ public: // Implements love::filesystem::File. bool open(Mode mode); bool close(); + bool isOpen() const; int64 getSize(); FileData *read(int64 size = ALL); int64 read(void *dst, int64 size); @@ -76,7 +77,7 @@ public: bool eof(); int64 tell(); bool seek(uint64 pos); - Mode getMode(); + Mode getMode() const; std::string getFilename() const; std::string getExtension() const; diff --git a/src/modules/filesystem/physfs/wrap_File.cpp b/src/modules/filesystem/physfs/wrap_File.cpp index 25862ee3b..16f73fa89 100644 --- a/src/modules/filesystem/physfs/wrap_File.cpp +++ b/src/modules/filesystem/physfs/wrap_File.cpp @@ -86,7 +86,14 @@ int w_File_open(lua_State *L) int w_File_close(lua_State *L) { File *file = luax_checkfile(L, 1); - lua_pushboolean(L, file->close() ? 1 : 0); + luax_pushboolean(L, file->close()); + return 1; +} + +int w_File_isOpen(lua_State *L) +{ + File *file = luax_checkfile(L, 1); + luax_pushboolean(L, file->isOpen()); return 1; } @@ -220,6 +227,7 @@ static const luaL_Reg functions[] = { "getSize", w_File_getSize }, { "open", w_File_open }, { "close", w_File_close }, + { "isOpen", w_File_isOpen }, { "read", w_File_read }, { "write", w_File_write }, { "eof", w_File_eof }, diff --git a/src/modules/filesystem/physfs/wrap_File.h b/src/modules/filesystem/physfs/wrap_File.h index 5a79c46ec..3eed83f73 100644 --- a/src/modules/filesystem/physfs/wrap_File.h +++ b/src/modules/filesystem/physfs/wrap_File.h @@ -37,6 +37,7 @@ File *luax_checkfile(lua_State *L, int idx); int w_File_getSize(lua_State *L); int w_File_open(lua_State *L); int w_File_close(lua_State *L); +int w_File_isOpen(lua_State *L); int w_File_read(lua_State *L); int w_File_write(lua_State *L); int w_File_eof(lua_State *L);