mirror of
https://github.com/love2d/love.git
synced 2026-08-18 11:44:15 +02:00
Finally abstracted constants properly. Changed how the event module works; wasn't really abstract before. Removed libs we're not going to use: native, signal.
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2009 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "File.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace filesystem
|
||||
{
|
||||
File::~File()
|
||||
{
|
||||
}
|
||||
|
||||
bool File::getConstant(const char * in, Mode & out)
|
||||
{
|
||||
return modes.find(in, out);
|
||||
}
|
||||
|
||||
bool File::getConstant(Mode in, const char *& out)
|
||||
{
|
||||
return modes.find(in, out);
|
||||
}
|
||||
|
||||
StringMap<File::Mode, File::MODE_MAX_ENUM>::Entry File::modeEntries[] =
|
||||
{
|
||||
{"c", File::CLOSED},
|
||||
{"r", File::READ},
|
||||
{"w", File::WRITE},
|
||||
{"w+", File::APPEND},
|
||||
};
|
||||
|
||||
StringMap<File::Mode, File::MODE_MAX_ENUM> File::modes(File::modeEntries, sizeof(File::modeEntries));
|
||||
|
||||
} // filesystem
|
||||
} // love
|
||||
@@ -27,6 +27,7 @@
|
||||
// LOVE
|
||||
#include <common/Data.h>
|
||||
#include <common/Object.h>
|
||||
#include <common/StringMap.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -49,6 +50,7 @@ namespace filesystem
|
||||
READ,
|
||||
WRITE,
|
||||
APPEND,
|
||||
MODE_MAX_ENUM
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -59,7 +61,7 @@ namespace filesystem
|
||||
/**
|
||||
* Destructor.
|
||||
**/
|
||||
virtual ~File(){};
|
||||
virtual ~File();
|
||||
|
||||
/**
|
||||
* Opens the file in a certain mode.
|
||||
@@ -158,6 +160,14 @@ namespace filesystem
|
||||
**/
|
||||
virtual std::string getExtension() const = 0;
|
||||
|
||||
static bool getConstant(const char * in, Mode & out);
|
||||
static bool getConstant(Mode in, const char *& out);
|
||||
|
||||
private:
|
||||
|
||||
static StringMap<Mode, MODE_MAX_ENUM>::Entry modeEntries[];
|
||||
static StringMap<Mode, MODE_MAX_ENUM> modes;
|
||||
|
||||
}; // File
|
||||
|
||||
} // filesystem
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
#include "File.h"
|
||||
|
||||
// STD
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
|
||||
// LOVE
|
||||
#include "Filesystem.h"
|
||||
@@ -46,6 +46,9 @@ namespace physfs
|
||||
|
||||
bool File::open(Mode mode)
|
||||
{
|
||||
if(mode == CLOSED)
|
||||
return true;
|
||||
|
||||
// File must exist if read mode.
|
||||
if((mode == READ))
|
||||
if(!PHYSFS_exists(filename.c_str()))
|
||||
@@ -73,9 +76,6 @@ namespace physfs
|
||||
case WRITE:
|
||||
file = PHYSFS_openWrite(filename.c_str());
|
||||
break;
|
||||
case CLOSED:
|
||||
// Heh. Case closed.
|
||||
return true;
|
||||
}
|
||||
|
||||
return (file != 0);
|
||||
|
||||
@@ -44,11 +44,14 @@ namespace physfs
|
||||
int w_File_open(lua_State * L)
|
||||
{
|
||||
File * file = luax_checkfile(L, 1);
|
||||
int mode = luaL_optint(L, 2, File::READ);
|
||||
File::Mode mode;
|
||||
|
||||
if(!File::getConstant(luaL_checkstring(L, 2), mode))
|
||||
return luaL_error(L, "Incorrect file open mode: %s", luaL_checkstring(L, 2));
|
||||
|
||||
try
|
||||
{
|
||||
lua_pushboolean(L, file->open((File::Mode)mode) ? 1 : 0);
|
||||
lua_pushboolean(L, file->open(mode) ? 1 : 0);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
|
||||
@@ -265,15 +265,6 @@ namespace physfs
|
||||
0
|
||||
};
|
||||
|
||||
// List of constants.
|
||||
static const Constant constants[] = {
|
||||
{ "file_closed", File::CLOSED },
|
||||
{ "file_read", File::READ },
|
||||
{ "file_write", File::WRITE },
|
||||
{ "file_append", File::APPEND },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int luaopen_love_filesystem(lua_State * L)
|
||||
{
|
||||
if(instance == 0)
|
||||
@@ -295,7 +286,6 @@ namespace physfs
|
||||
w.flags = MODULE_FILESYSTEM_T;
|
||||
w.functions = functions;
|
||||
w.types = types;
|
||||
w.constants = constants;
|
||||
|
||||
return luax_register_module(L, w);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user