Added File:isOpen

This commit is contained in:
Alex Szpakowski
2013-06-27 02:23:56 -03:00
parent 80122d67e6
commit 186bcae7cb
5 changed files with 24 additions and 4 deletions
+6 -1
View File
@@ -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.
+6 -1
View File
@@ -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;
}
+2 -1
View File
@@ -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;
+9 -1
View File
@@ -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 },
@@ -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);