Commits

Alex Szpakowski committed 0dc4a7d

Added File:isOpen

Comments (0)

Files changed (5)

src/modules/filesystem/File.h

 	virtual bool close() = 0;
 
 	/**
+	 * Gets whether the file is open.
+	 **/
+	virtual bool isOpen() const = 0;
+
+	/**
 	 * Gets the size of the file.
 	 *
 	 * @return The size of the file.
 	 * 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.

src/modules/filesystem/physfs/File.cpp

 	return true;
 }
 
+bool File::isOpen() const
+{
+	return mode != CLOSED && file != 0;
+}
+
 int64 File::getSize()
 {
 	// If the file is closed, open it to
 		return std::string();
 }
 
-filesystem::File::Mode File::getMode()
+filesystem::File::Mode File::getMode() const
 {
 	return mode;
 }

src/modules/filesystem/physfs/File.h

 	// 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);
 	bool eof();
 	int64 tell();
 	bool seek(uint64 pos);
-	Mode getMode();
+	Mode getMode() const;
 	std::string getFilename() const;
 	std::string getExtension() const;
 

src/modules/filesystem/physfs/wrap_File.cpp

 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;
 }
 
 	{ "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 },

src/modules/filesystem/physfs/wrap_File.h

 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);