mirror of
https://github.com/love2d/love.git
synced 2026-08-12 08:30:56 +02:00
Add love.filesystem.openNativeFile (name may change in the future)
This commit is contained in:
@@ -20,6 +20,7 @@
|
||||
|
||||
// LOVE
|
||||
#include "Filesystem.h"
|
||||
#include "NativeFile.h"
|
||||
#include "common/utf8.h"
|
||||
|
||||
// Assume POSIX or Visual Studio.
|
||||
@@ -67,6 +68,11 @@ bool Filesystem::isAndroidSaveExternal() const
|
||||
return useExternal;
|
||||
}
|
||||
|
||||
NativeFile *Filesystem::openNativeFile(const char *path, File::Mode mode) const
|
||||
{
|
||||
return new NativeFile(path, mode);
|
||||
}
|
||||
|
||||
FileData *Filesystem::newFileData(const void *data, size_t size, const char *filename) const
|
||||
{
|
||||
FileData *fd = new FileData(size, std::string(filename));
|
||||
|
||||
@@ -58,6 +58,8 @@ namespace love
|
||||
namespace filesystem
|
||||
{
|
||||
|
||||
class NativeFile;
|
||||
|
||||
class Filesystem : public Module
|
||||
{
|
||||
public:
|
||||
@@ -173,6 +175,8 @@ public:
|
||||
**/
|
||||
virtual File *openFile(const char *filename, File::Mode mode) const = 0;
|
||||
|
||||
NativeFile *openNativeFile(const char *path, File::Mode mode) const;
|
||||
|
||||
/**
|
||||
* Creates a new FileData object. Data will be copied.
|
||||
* @param data Pointer to the data.
|
||||
@@ -328,7 +332,7 @@ private:
|
||||
bool getRealPathType(const std::string &path, FileType &ftype) const;
|
||||
|
||||
// Should we save external or internal for Android
|
||||
bool useExternal;
|
||||
bool useExternal = false;
|
||||
|
||||
}; // Filesystem
|
||||
|
||||
|
||||
@@ -251,6 +251,30 @@ int w_openFile(lua_State *L)
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_openNativeFile(lua_State *L)
|
||||
{
|
||||
const char *path = luaL_checkstring(L, 1);
|
||||
const char *modestr = luaL_checkstring(L, 2);
|
||||
|
||||
File::Mode mode = File::MODE_CLOSED;
|
||||
if (!File::getConstant(modestr, mode))
|
||||
return luax_enumerror(L, "file open mode", File::getConstants(mode), modestr);
|
||||
|
||||
File *t = nullptr;
|
||||
try
|
||||
{
|
||||
t = instance()->openNativeFile(path, mode);
|
||||
}
|
||||
catch (love::Exception &e)
|
||||
{
|
||||
return luax_ioError(L, "%s", e.what());
|
||||
}
|
||||
|
||||
luax_pushtype(L, t);
|
||||
t->release();
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newFile(lua_State* L)
|
||||
{
|
||||
luax_markdeprecated(L, 1, "love.filesystem.newFile", API_FUNCTION, DEPRECATED_RENAMED, "love.filesystem.openFile");
|
||||
@@ -1027,6 +1051,7 @@ static const luaL_Reg functions[] =
|
||||
{ "unmountFullPath", w_unmountFullPath },
|
||||
{ "unmountCommonPath", w_unmountCommonPath },
|
||||
{ "openFile", w_openFile },
|
||||
{ "openNativeFile", w_openNativeFile },
|
||||
{ "getFullCommonPath", w_getFullCommonPath },
|
||||
{ "getWorkingDirectory", w_getWorkingDirectory },
|
||||
{ "getUserDirectory", w_getUserDirectory },
|
||||
|
||||
Reference in New Issue
Block a user