mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Automated formatting fix
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2011 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
|
||||
@@ -38,7 +38,7 @@ namespace filesystem
|
||||
return modes.find(in, out);
|
||||
}
|
||||
|
||||
StringMap<File::Mode, File::MODE_MAX_ENUM>::Entry File::modeEntries[] =
|
||||
StringMap<File::Mode, File::MODE_MAX_ENUM>::Entry File::modeEntries[] =
|
||||
{
|
||||
{"c", File::CLOSED},
|
||||
{"r", File::READ},
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2011 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
|
||||
@@ -34,7 +34,7 @@ namespace love
|
||||
namespace filesystem
|
||||
{
|
||||
/**
|
||||
* A File interface, providing generic means of reading from and
|
||||
* A File interface, providing generic means of reading from and
|
||||
* writing to files.
|
||||
**/
|
||||
class File : public Object
|
||||
@@ -65,7 +65,7 @@ namespace filesystem
|
||||
|
||||
/**
|
||||
* Opens the file in a certain mode.
|
||||
*
|
||||
*
|
||||
* @param mode READ, WRITE, APPEND.
|
||||
* @return True if successful, false otherwise.
|
||||
**/
|
||||
@@ -73,21 +73,21 @@ namespace filesystem
|
||||
|
||||
/**
|
||||
* Closes the file.
|
||||
*
|
||||
*
|
||||
* @return True if successful, false otherwise.
|
||||
**/
|
||||
virtual bool close() = 0;
|
||||
|
||||
/**
|
||||
* Gets the size of the file.
|
||||
*
|
||||
*
|
||||
* @return The size of the file.
|
||||
**/
|
||||
virtual unsigned int getSize() = 0;
|
||||
|
||||
/**
|
||||
* Reads data from the file and allocates a Data object.
|
||||
*
|
||||
*
|
||||
* @param size The number of bytes to attempt reading, or -1 for EOF.
|
||||
* @return A newly allocated Data object.
|
||||
**/
|
||||
@@ -95,7 +95,7 @@ namespace filesystem
|
||||
|
||||
/**
|
||||
* Reads data into the destination buffer.
|
||||
*
|
||||
*
|
||||
* @param dst The destination buffer.
|
||||
* @param size The number of bytes to attempt reading.
|
||||
* @return The number of bytes actually read.
|
||||
@@ -104,7 +104,7 @@ namespace filesystem
|
||||
|
||||
/**
|
||||
* Writes data into the File.
|
||||
*
|
||||
*
|
||||
* @param data The source buffer.
|
||||
* @param size The size of the buffer.
|
||||
* @return True of success, false otherwise.
|
||||
@@ -113,7 +113,7 @@ namespace filesystem
|
||||
|
||||
/**
|
||||
* Writes a Data object into the File.
|
||||
*
|
||||
*
|
||||
* @param data The data object to write into the file.
|
||||
* @param size The number of bytes to attempt writing, or -1 for everything.
|
||||
* @return True of success, false otherwise.
|
||||
@@ -122,28 +122,28 @@ namespace filesystem
|
||||
|
||||
/**
|
||||
* Checks whether we are currently at end-of-file.
|
||||
*
|
||||
*
|
||||
* @return True if EOF, false otherwise.
|
||||
**/
|
||||
virtual bool eof() = 0;
|
||||
|
||||
/**
|
||||
* Gets the current position in the File.
|
||||
*
|
||||
*
|
||||
* @return The current byte position in the File.
|
||||
**/
|
||||
virtual int tell() = 0;
|
||||
|
||||
/**
|
||||
* Seeks to a certain position in the File.
|
||||
*
|
||||
*
|
||||
* @param pos The byte position in the file.
|
||||
* @return True on success, false otherwise.
|
||||
**/
|
||||
virtual bool seek(int pos) = 0;
|
||||
|
||||
/**
|
||||
* Gets the current mode 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;
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2011 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
|
||||
@@ -30,7 +30,7 @@ namespace filesystem
|
||||
FileData::FileData(int size, const std::string & filename)
|
||||
: data(new char[size]), size(size), filename(filename)
|
||||
{
|
||||
if(filename.rfind('.') != std::string::npos)
|
||||
if (filename.rfind('.') != std::string::npos)
|
||||
extension = filename.substr(filename.rfind('.')+1);
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ namespace filesystem
|
||||
return decoders.find(in, out);
|
||||
}
|
||||
|
||||
StringMap<FileData::Decoder, FileData::DECODE_MAX_ENUM>::Entry FileData::decoderEntries[] =
|
||||
StringMap<FileData::Decoder, FileData::DECODE_MAX_ENUM>::Entry FileData::decoderEntries[] =
|
||||
{
|
||||
{"file", FileData::FILE},
|
||||
{"base64", FileData::BASE64},
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2011 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
|
||||
@@ -27,7 +27,7 @@
|
||||
#include <common/StringMap.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
{
|
||||
namespace filesystem
|
||||
{
|
||||
class FileData : public Data
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2011 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
|
||||
@@ -35,7 +35,7 @@ namespace physfs
|
||||
{
|
||||
extern bool hack_setupWriteDirectory();
|
||||
|
||||
File::File(std::string filename)
|
||||
File::File(std::string filename)
|
||||
: filename(filename), file(0), mode(filesystem::File::CLOSED)
|
||||
{
|
||||
}
|
||||
@@ -45,22 +45,22 @@ namespace physfs
|
||||
if (mode != CLOSED)
|
||||
close();
|
||||
}
|
||||
|
||||
|
||||
bool File::open(Mode mode)
|
||||
{
|
||||
if(mode == CLOSED)
|
||||
if (mode == CLOSED)
|
||||
return true;
|
||||
|
||||
// File must exist if read mode.
|
||||
if((mode == READ) && !PHYSFS_exists(filename.c_str()))
|
||||
if ((mode == READ) && !PHYSFS_exists(filename.c_str()))
|
||||
throw love::Exception("Could not open file %s. Does not exist.", filename.c_str());
|
||||
|
||||
// Check whether the write directory is set.
|
||||
if((mode == APPEND || mode == WRITE) && (PHYSFS_getWriteDir() == 0) && !hack_setupWriteDirectory())
|
||||
if ((mode == APPEND || mode == WRITE) && (PHYSFS_getWriteDir() == 0) && !hack_setupWriteDirectory())
|
||||
throw love::Exception("Could not set write directory.");
|
||||
|
||||
// File already open?
|
||||
if(file != 0)
|
||||
if (file != 0)
|
||||
return false;
|
||||
|
||||
this->mode = mode;
|
||||
@@ -82,10 +82,10 @@ namespace physfs
|
||||
|
||||
return (file != 0);
|
||||
}
|
||||
|
||||
|
||||
bool File::close()
|
||||
{
|
||||
if(!PHYSFS_close(file))
|
||||
if (!PHYSFS_close(file))
|
||||
return false;
|
||||
mode = CLOSED;
|
||||
file = 0;
|
||||
@@ -96,7 +96,7 @@ namespace physfs
|
||||
{
|
||||
// If the file is closed, open it to
|
||||
// check the size.
|
||||
if(file == 0)
|
||||
if (file == 0)
|
||||
{
|
||||
open(READ);
|
||||
unsigned int size = (unsigned int)PHYSFS_fileLength(file);
|
||||
@@ -112,7 +112,7 @@ namespace physfs
|
||||
{
|
||||
bool isOpen = (file != 0);
|
||||
|
||||
if(!isOpen && !open(READ))
|
||||
if (!isOpen && !open(READ))
|
||||
throw love::Exception("Could not read file %s.", filename.c_str());
|
||||
|
||||
int max = (int)PHYSFS_fileLength(file);
|
||||
@@ -123,7 +123,7 @@ namespace physfs
|
||||
|
||||
read(fileData->getData(), size);
|
||||
|
||||
if(!isOpen)
|
||||
if (!isOpen)
|
||||
close();
|
||||
|
||||
return fileData;
|
||||
@@ -133,7 +133,7 @@ namespace physfs
|
||||
{
|
||||
bool isOpen = (file != 0);
|
||||
|
||||
if(!isOpen)
|
||||
if (!isOpen)
|
||||
open(READ);
|
||||
|
||||
int max = (int)PHYSFS_fileLength(file);
|
||||
@@ -142,7 +142,7 @@ namespace physfs
|
||||
|
||||
int read = (int)PHYSFS_read(file, dst, 1, size);
|
||||
|
||||
if(!isOpen)
|
||||
if (!isOpen)
|
||||
close();
|
||||
|
||||
return read;
|
||||
@@ -150,14 +150,14 @@ namespace physfs
|
||||
|
||||
bool File::write(const void * data, int size)
|
||||
{
|
||||
if(file == 0)
|
||||
if (file == 0)
|
||||
throw love::Exception("Could not write to file. File not open.");
|
||||
|
||||
// Try to write.
|
||||
int written = static_cast<int>(PHYSFS_write(file, data, 1, size));
|
||||
|
||||
// Check that correct amount of data was written.
|
||||
if(written != size)
|
||||
if (written != size)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -187,14 +187,14 @@ namespace physfs
|
||||
|
||||
bool File::eof()
|
||||
{
|
||||
if(file == 0 || test_eof(this, file))
|
||||
if (file == 0 || test_eof(this, file))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
int File::tell()
|
||||
{
|
||||
if(file == 0)
|
||||
if (file == 0)
|
||||
return -1;
|
||||
|
||||
return (int)PHYSFS_tell(file);
|
||||
@@ -202,10 +202,10 @@ namespace physfs
|
||||
|
||||
bool File::seek(int pos)
|
||||
{
|
||||
if(file == 0)
|
||||
if (file == 0)
|
||||
return false;
|
||||
|
||||
if(!PHYSFS_seek(file, (PHYSFS_uint64)pos))
|
||||
|
||||
if (!PHYSFS_seek(file, (PHYSFS_uint64)pos))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@@ -219,7 +219,7 @@ namespace physfs
|
||||
{
|
||||
std::string::size_type idx = filename.rfind('.');
|
||||
|
||||
if(idx != std::string::npos)
|
||||
if (idx != std::string::npos)
|
||||
return filename.substr(idx+1);
|
||||
else
|
||||
return std::string();
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2011 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
|
||||
@@ -63,7 +63,7 @@ namespace physfs
|
||||
File(std::string filename);
|
||||
|
||||
virtual ~File();
|
||||
|
||||
|
||||
// Implements love::filesystem::File.
|
||||
bool open(Mode mode);
|
||||
bool close();
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace physfs
|
||||
|
||||
Filesystem::~Filesystem()
|
||||
{
|
||||
if(isInited)
|
||||
if (isInited)
|
||||
{
|
||||
isInited = false;
|
||||
PHYSFS_deinit();
|
||||
@@ -54,7 +54,7 @@ namespace physfs
|
||||
|
||||
void Filesystem::init(const char * arg0)
|
||||
{
|
||||
if(!PHYSFS_init(arg0))
|
||||
if (!PHYSFS_init(arg0))
|
||||
throw Exception(PHYSFS_getLastError());
|
||||
isInited = true;
|
||||
}
|
||||
@@ -76,7 +76,7 @@ namespace physfs
|
||||
|
||||
bool Filesystem::setIdentity( const char * ident )
|
||||
{
|
||||
if(!isInited)
|
||||
if (!isInited)
|
||||
return false;
|
||||
|
||||
// Store the save directory.
|
||||
@@ -106,15 +106,15 @@ namespace physfs
|
||||
|
||||
bool Filesystem::setSource(const char * source)
|
||||
{
|
||||
if(!isInited)
|
||||
if (!isInited)
|
||||
return false;
|
||||
|
||||
// Check whether directory is already set.
|
||||
if(!game_source.empty())
|
||||
if (!game_source.empty())
|
||||
return false;
|
||||
|
||||
// Add the directory.
|
||||
if(!PHYSFS_addToSearchPath(source, 1))
|
||||
if (!PHYSFS_addToSearchPath(source, 1))
|
||||
return false;
|
||||
|
||||
// Save the game source.
|
||||
@@ -125,16 +125,16 @@ namespace physfs
|
||||
|
||||
bool Filesystem::setupWriteDirectory()
|
||||
{
|
||||
if(!isInited)
|
||||
if (!isInited)
|
||||
return false;
|
||||
|
||||
// These must all be set.
|
||||
if(save_identity.empty() || save_path_full.empty() || save_path_relative.empty())
|
||||
if (save_identity.empty() || save_path_full.empty() || save_path_relative.empty())
|
||||
return false;
|
||||
|
||||
// Set the appdata folder as writable directory.
|
||||
// (We must create the save folder before mounting it).
|
||||
if(!PHYSFS_setWriteDir(getAppdataDirectory()))
|
||||
if (!PHYSFS_setWriteDir(getAppdataDirectory()))
|
||||
return false;
|
||||
|
||||
// Create the save folder. (We're now "at" %APPDATA%).
|
||||
@@ -144,18 +144,18 @@ namespace physfs
|
||||
else
|
||||
success = mkdir(save_path_relative.c_str());
|
||||
|
||||
if(!success)
|
||||
if (!success)
|
||||
{
|
||||
PHYSFS_setWriteDir(0); // Clear the write directory in case of error.
|
||||
return false;
|
||||
}
|
||||
|
||||
// Set the final write directory.
|
||||
if(!PHYSFS_setWriteDir(save_path_full.c_str()))
|
||||
if (!PHYSFS_setWriteDir(save_path_full.c_str()))
|
||||
return false;
|
||||
|
||||
// Add the directory. (Will not be readded if already present).
|
||||
if(!PHYSFS_addToSearchPath(save_path_full.c_str(), 0))
|
||||
if (!PHYSFS_addToSearchPath(save_path_full.c_str(), 0))
|
||||
{
|
||||
PHYSFS_setWriteDir(0); // Clear the write directory in case of error.
|
||||
return false;
|
||||
@@ -195,7 +195,7 @@ namespace physfs
|
||||
|
||||
const char * Filesystem::getWorkingDirectory()
|
||||
{
|
||||
if(cwd.empty())
|
||||
if (cwd.empty())
|
||||
{
|
||||
#ifdef LOVE_WINDOWS
|
||||
|
||||
@@ -206,7 +206,7 @@ namespace physfs
|
||||
#else
|
||||
char * cwd_char = new char[LOVE_MAX_PATH];
|
||||
|
||||
if(getcwd(cwd_char, LOVE_MAX_PATH))
|
||||
if (getcwd(cwd_char, LOVE_MAX_PATH))
|
||||
cwd = cwd_char; // if getcwd fails, cwd_char (and thus cwd) will still be empty
|
||||
|
||||
delete [] cwd_char;
|
||||
@@ -224,7 +224,7 @@ namespace physfs
|
||||
const char * Filesystem::getAppdataDirectory()
|
||||
{
|
||||
#ifdef LOVE_WINDOWS
|
||||
if(appdata.empty())
|
||||
if (appdata.empty())
|
||||
{
|
||||
wchar_t * w_appdata = _wgetenv(TEXT("APPDATA"));
|
||||
appdata = to_utf8(w_appdata);
|
||||
@@ -232,7 +232,7 @@ namespace physfs
|
||||
}
|
||||
return appdata.c_str();
|
||||
#elif defined(LOVE_MACOSX)
|
||||
if(appdata.empty())
|
||||
if (appdata.empty())
|
||||
{
|
||||
std::string udir = getUserDirectory();
|
||||
udir.append("/Library/Application Support");
|
||||
@@ -240,7 +240,7 @@ namespace physfs
|
||||
}
|
||||
return appdata.c_str();
|
||||
#elif defined(LOVE_LINUX)
|
||||
if(appdata.empty())
|
||||
if (appdata.empty())
|
||||
{
|
||||
char * xdgdatahome = getenv("XDG_DATA_HOME");
|
||||
if (!xdgdatahome)
|
||||
@@ -262,14 +262,14 @@ namespace physfs
|
||||
|
||||
bool Filesystem::exists(const char * file)
|
||||
{
|
||||
if(PHYSFS_exists(file))
|
||||
if (PHYSFS_exists(file))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Filesystem::isDirectory(const char * file)
|
||||
{
|
||||
if(PHYSFS_isDirectory(file))
|
||||
if (PHYSFS_isDirectory(file))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
@@ -281,20 +281,20 @@ namespace physfs
|
||||
|
||||
bool Filesystem::mkdir(const char * file)
|
||||
{
|
||||
if(PHYSFS_getWriteDir() == 0 && !setupWriteDirectory())
|
||||
if (PHYSFS_getWriteDir() == 0 && !setupWriteDirectory())
|
||||
return false;
|
||||
|
||||
if(!PHYSFS_mkdir(file))
|
||||
if (!PHYSFS_mkdir(file))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Filesystem::remove(const char * file)
|
||||
{
|
||||
if(PHYSFS_getWriteDir() == 0 && !setupWriteDirectory())
|
||||
if (PHYSFS_getWriteDir() == 0 && !setupWriteDirectory())
|
||||
return false;
|
||||
|
||||
if(!PHYSFS_delete(file))
|
||||
if (!PHYSFS_delete(file))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
@@ -305,7 +305,7 @@ namespace physfs
|
||||
// on-the-fly, or passed as a parameter.
|
||||
File * file;
|
||||
|
||||
if(lua_isstring(L, 1))
|
||||
if (lua_isstring(L, 1))
|
||||
{
|
||||
// Create the file.
|
||||
file = newFile(lua_tostring(L, 1));
|
||||
@@ -321,12 +321,12 @@ namespace physfs
|
||||
Data * data = file->read(count);
|
||||
|
||||
// Error check.
|
||||
if(data == 0)
|
||||
if (data == 0)
|
||||
return luaL_error(L, "File could not be read.");
|
||||
|
||||
// Close and delete the file, if we created it.
|
||||
// (I.e. if the first parameter is a string).
|
||||
if(lua_isstring(L, 1))
|
||||
if (lua_isstring(L, 1))
|
||||
file->release();
|
||||
|
||||
// Push the string.
|
||||
@@ -349,10 +349,10 @@ namespace physfs
|
||||
|
||||
// We know for sure that we need a second parameter, so
|
||||
// let's check that first.
|
||||
if(lua_isnoneornil(L, 2))
|
||||
if (lua_isnoneornil(L, 2))
|
||||
return luaL_error(L, "Second argument needed.");
|
||||
|
||||
if(lua_isstring(L, 1))
|
||||
if (lua_isstring(L, 1))
|
||||
{
|
||||
// Create the file.
|
||||
file = newFile(lua_tostring(L, 1));
|
||||
@@ -363,26 +363,31 @@ namespace physfs
|
||||
// Get the current mode of the file.
|
||||
File::Mode mode = file->getMode();
|
||||
|
||||
if(mode == File::CLOSED)
|
||||
if (mode == File::CLOSED)
|
||||
{
|
||||
// It should be possible to use append mode, but
|
||||
// normal File::Mode::Write is the default.
|
||||
int mode = luaL_optint(L, 4, File::WRITE);
|
||||
|
||||
// Open the file.
|
||||
if(!file->open((File::Mode)mode))
|
||||
if (!file->open((File::Mode)mode))
|
||||
return luaL_error(L, "Could not open file.");
|
||||
}
|
||||
|
||||
size_t length = 0;
|
||||
const char * input;
|
||||
if(lua_isstring(L, 2)) {
|
||||
if (lua_isstring(L, 2))
|
||||
{
|
||||
input = lua_tolstring(L, 2, &length);
|
||||
} else if (luax_istype(L, 2, DATA_T)) {
|
||||
}
|
||||
else if (luax_istype(L, 2, DATA_T))
|
||||
{
|
||||
love::Data * data = luax_totype<love::Data>(L, 2, "Data", DATA_T);
|
||||
length = data->getSize();
|
||||
input = (char *)data->getData();
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
return luaL_error(L, "Expected string or data for argument #2.");
|
||||
}
|
||||
|
||||
@@ -394,14 +399,14 @@ namespace physfs
|
||||
|
||||
// Close and delete the file, if we created
|
||||
// it in this function.
|
||||
if(lua_isstring(L, 1))
|
||||
if (lua_isstring(L, 1))
|
||||
{
|
||||
// Kill the file if "we" created it.
|
||||
file->close();
|
||||
file->release();
|
||||
}
|
||||
|
||||
if(!success)
|
||||
if (!success)
|
||||
return luaL_error(L, "Data could not be written.");
|
||||
|
||||
lua_pushboolean(L, success);
|
||||
@@ -412,12 +417,12 @@ namespace physfs
|
||||
{
|
||||
int n = lua_gettop(L);
|
||||
|
||||
if( n != 1 )
|
||||
if ( n != 1 )
|
||||
return luaL_error(L, "Function requires a single parameter.");
|
||||
|
||||
int type = lua_type(L, 1);
|
||||
|
||||
if(type != LUA_TSTRING)
|
||||
if (type != LUA_TSTRING)
|
||||
return luaL_error(L, "Function requires parameter of type string.");
|
||||
|
||||
const char * dir = lua_tostring(L, 1);
|
||||
@@ -444,10 +449,10 @@ namespace physfs
|
||||
{
|
||||
File * file;
|
||||
|
||||
if(lua_isstring(L, 1))
|
||||
if (lua_isstring(L, 1))
|
||||
{
|
||||
file = newFile(lua_tostring(L, 1));
|
||||
if(!file->open(File::READ))
|
||||
if (!file->open(File::READ))
|
||||
return luaL_error(L, "Could not open file %s.\n", lua_tostring(L, 1));
|
||||
lua_pop(L, 1);
|
||||
|
||||
@@ -458,7 +463,7 @@ namespace physfs
|
||||
return luaL_error(L, "Expected filename.");
|
||||
|
||||
// Reset the file position.
|
||||
if(!file->seek(0))
|
||||
if (!file->seek(0))
|
||||
return luaL_error(L, "File does not appear to be open.\n");
|
||||
|
||||
lua_pushcclosure(L, lines_i, 2);
|
||||
@@ -480,34 +485,34 @@ namespace physfs
|
||||
int newline = -1;
|
||||
int totalread = 0;
|
||||
|
||||
while(!file->eof())
|
||||
while (!file->eof())
|
||||
{
|
||||
int current = file->tell();
|
||||
int read = file->read(buf, bufsize);
|
||||
totalread += read;
|
||||
|
||||
if(read < 0)
|
||||
if (read < 0)
|
||||
return luaL_error(L, "Readline failed!");
|
||||
|
||||
for(int i = 0;i<read;i++)
|
||||
for (int i = 0;i<read;i++)
|
||||
{
|
||||
if(buf[i] == '\n')
|
||||
if (buf[i] == '\n')
|
||||
{
|
||||
newline = current+i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(newline > 0)
|
||||
if (newline > 0)
|
||||
break;
|
||||
}
|
||||
|
||||
// Special case for the last "line".
|
||||
if(newline <= 0 && file->eof() && totalread > 0)
|
||||
if (newline <= 0 && file->eof() && totalread > 0)
|
||||
newline = pos + totalread;
|
||||
|
||||
// We've got a newline.
|
||||
if(newline > 0)
|
||||
if (newline > 0)
|
||||
{
|
||||
// Ok, we've got a line.
|
||||
int linesize = (newline-pos);
|
||||
@@ -517,10 +522,10 @@ namespace physfs
|
||||
|
||||
// Read it.
|
||||
file->seek(pos);
|
||||
if(file->read(str, linesize) == -1)
|
||||
if (file->read(str, linesize) == -1)
|
||||
return luaL_error(L, "Read error.");
|
||||
|
||||
if(str[linesize-1]=='\r')
|
||||
if (str[linesize-1]=='\r')
|
||||
linesize -= 1;
|
||||
|
||||
lua_pushlstring(L, str, linesize);
|
||||
@@ -529,13 +534,13 @@ namespace physfs
|
||||
delete[] str;
|
||||
|
||||
// Set the beginning of the next line.
|
||||
if(!file->eof())
|
||||
if (!file->eof())
|
||||
file->seek(newline+1);
|
||||
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(close)
|
||||
if (close)
|
||||
{
|
||||
file->close();
|
||||
file->release();
|
||||
@@ -550,13 +555,13 @@ namespace physfs
|
||||
luax_assert_argc(L, 1, 1);
|
||||
|
||||
// Must be string.
|
||||
if(!lua_isstring(L, -1))
|
||||
if (!lua_isstring(L, -1))
|
||||
return luaL_error(L, "The argument must be a string.");
|
||||
|
||||
std::string filename = lua_tostring(L, -1);
|
||||
|
||||
// The file must exist.
|
||||
if(!exists(filename.c_str()))
|
||||
if (!exists(filename.c_str()))
|
||||
return luaL_error(L, "File %s does not exist.", filename.c_str());
|
||||
|
||||
// Create the file.
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2011 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
|
||||
@@ -53,14 +53,14 @@ namespace physfs
|
||||
File * file = luax_checkfile(L, 1);
|
||||
File::Mode mode;
|
||||
|
||||
if(!File::getConstant(luaL_checkstring(L, 2), 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(mode) ? 1 : 0);
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
@@ -84,7 +84,7 @@ namespace physfs
|
||||
{
|
||||
d = file->read(luaL_optint(L, 2, file->getSize()));
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
@@ -107,18 +107,20 @@ namespace physfs
|
||||
{
|
||||
result = file->write(lua_tostring(L, 2), luaL_optint(L, 3, lua_objlen(L, 2)));
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
else if( luax_istype(L, 2, DATA_T)) {
|
||||
else if ( luax_istype(L, 2, DATA_T))
|
||||
{
|
||||
try
|
||||
{
|
||||
love::Data * data = luax_totype<love::Data>(L, 2, "Data", DATA_T);
|
||||
result = file->write(data, luaL_optint(L, 3, data->getSize()));
|
||||
} catch(Exception e)
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
@@ -159,7 +161,7 @@ namespace physfs
|
||||
{
|
||||
File * file;
|
||||
|
||||
if(luax_istype(L, 1, FILESYSTEM_FILE_T))
|
||||
if (luax_istype(L, 1, FILESYSTEM_FILE_T))
|
||||
{
|
||||
file = luax_checktype<File>(L, 1, "File", FILESYSTEM_FILE_T);
|
||||
lua_pushnumber(L, 0); // 0 = do not close.
|
||||
@@ -168,14 +170,14 @@ namespace physfs
|
||||
return luaL_error(L, "Expected file handle.");
|
||||
|
||||
// Reset the file position.
|
||||
if(!file->seek(0))
|
||||
if (!file->seek(0))
|
||||
return luaL_error(L, "File does not appear to be open.\n");
|
||||
|
||||
lua_pushcclosure(L, Filesystem::lines_i, 2);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "getSize", w_File_getSize },
|
||||
{ "open", w_File_open },
|
||||
{ "close", w_File_close },
|
||||
@@ -192,7 +194,7 @@ namespace physfs
|
||||
{
|
||||
return luax_register_type(L, "File", functions);
|
||||
}
|
||||
|
||||
|
||||
} // physfs
|
||||
} // filesystem
|
||||
} // love
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2011 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
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2011 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
|
||||
@@ -63,7 +63,7 @@ namespace physfs
|
||||
{
|
||||
return luax_register_type(L, "FileData", w_FileData_functions);
|
||||
}
|
||||
|
||||
|
||||
} // physfs
|
||||
} // filesystem
|
||||
} // love
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2011 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
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace physfs
|
||||
|
||||
bool hack_setupWriteDirectory()
|
||||
{
|
||||
if(instance != 0)
|
||||
if (instance != 0)
|
||||
return instance->setupWriteDirectory();
|
||||
return false;
|
||||
}
|
||||
@@ -44,7 +44,7 @@ namespace physfs
|
||||
{
|
||||
instance->init(arg0);
|
||||
}
|
||||
catch(Exception & e)
|
||||
catch (Exception & e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
@@ -64,7 +64,7 @@ namespace physfs
|
||||
{
|
||||
const char * arg = luaL_checkstring(L, 1);
|
||||
|
||||
if(!instance->setIdentity(arg))
|
||||
if (!instance->setIdentity(arg))
|
||||
return luaL_error(L, "Could not set write directory.");
|
||||
|
||||
return 0;
|
||||
@@ -74,7 +74,7 @@ namespace physfs
|
||||
{
|
||||
const char * arg = luaL_checkstring(L, 1);
|
||||
|
||||
if(!instance->setSource(arg))
|
||||
if (!instance->setSource(arg))
|
||||
return luaL_error(L, "Could not set source.");
|
||||
|
||||
return 0;
|
||||
@@ -88,7 +88,7 @@ namespace physfs
|
||||
{
|
||||
t = instance->newFile(filename);
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
@@ -98,9 +98,9 @@ namespace physfs
|
||||
|
||||
int w_newFileData(lua_State * L)
|
||||
{
|
||||
if(!lua_isstring(L, 1))
|
||||
if (!lua_isstring(L, 1))
|
||||
return luaL_error(L, "String expected.");
|
||||
if(!lua_isstring(L, 2))
|
||||
if (!lua_isstring(L, 2))
|
||||
return luaL_error(L, "String expected.");
|
||||
|
||||
size_t length = 0;
|
||||
@@ -110,7 +110,7 @@ namespace physfs
|
||||
|
||||
FileData::Decoder decoder = FileData::FILE;
|
||||
|
||||
if(decstr)
|
||||
if (decstr)
|
||||
FileData::getConstant(decstr, decoder);
|
||||
|
||||
FileData * t = 0;
|
||||
@@ -196,7 +196,7 @@ namespace physfs
|
||||
{
|
||||
return instance->read(L);
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
@@ -208,7 +208,7 @@ namespace physfs
|
||||
{
|
||||
return instance->write(L);
|
||||
}
|
||||
catch(Exception e)
|
||||
catch (Exception e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
@@ -233,10 +233,12 @@ namespace physfs
|
||||
|
||||
int w_load(lua_State * L)
|
||||
{
|
||||
try {
|
||||
try
|
||||
{
|
||||
return instance->load(L);
|
||||
}
|
||||
catch (love::Exception & e) {
|
||||
catch (love::Exception & e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
}
|
||||
@@ -255,16 +257,16 @@ namespace physfs
|
||||
|
||||
int size = tmp.size();
|
||||
|
||||
for(int i=0;i<size-4;i++)
|
||||
for (int i=0;i<size-4;i++)
|
||||
{
|
||||
if(tmp[i] == '.')
|
||||
if (tmp[i] == '.')
|
||||
{
|
||||
tmp[i] = '/';
|
||||
}
|
||||
}
|
||||
|
||||
// Check whether file exists.
|
||||
if(instance->exists(tmp.c_str()))
|
||||
if (instance->exists(tmp.c_str()))
|
||||
{
|
||||
lua_pop(L, 1);
|
||||
lua_pushstring(L, tmp.c_str());
|
||||
@@ -274,9 +276,9 @@ namespace physfs
|
||||
|
||||
tmp = filename;
|
||||
size = tmp.size();
|
||||
for(int i=0;i<size;i++)
|
||||
for (int i=0;i<size;i++)
|
||||
{
|
||||
if(tmp[i] == '.')
|
||||
if (tmp[i] == '.')
|
||||
{
|
||||
tmp[i] = '/';
|
||||
}
|
||||
@@ -285,7 +287,8 @@ namespace physfs
|
||||
if (instance->isDirectory(tmp.c_str()))
|
||||
{
|
||||
tmp += "/init.lua";
|
||||
if (instance->exists(tmp.c_str())) {
|
||||
if (instance->exists(tmp.c_str()))
|
||||
{
|
||||
lua_pop(L, 1);
|
||||
lua_pushstring(L, tmp.c_str());
|
||||
// Ok, load it.
|
||||
@@ -384,7 +387,7 @@ namespace physfs
|
||||
|
||||
int luaopen_love_filesystem(lua_State * L)
|
||||
{
|
||||
if(instance == 0)
|
||||
if (instance == 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -392,7 +395,7 @@ namespace physfs
|
||||
love::luax_register_searcher(L, loader, 1);
|
||||
love::luax_register_searcher(L, extloader, 2);
|
||||
}
|
||||
catch(Exception & e)
|
||||
catch (Exception & e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2011 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
|
||||
|
||||
Reference in New Issue
Block a user