Added many comments, and changed function names for wrapper functions.

This commit is contained in:
rude
2009-08-09 21:08:55 +02:00
parent f2adfd53f2
commit ba1a75e547
103 changed files with 2608 additions and 2391 deletions
+6 -6
View File
@@ -64,10 +64,10 @@ namespace physfs
save_identity = std::string(ident);
// Generate the relative path to the game save folder.
save_path_relative = std::string(LOVE_APPDATA_FOLDER LOVE_PATH_SEPARATOR) + save_identity;
save_path_relative = std::string(APPDATA_FOLDER PATH_SEPARATOR) + save_identity;
// Generate the full path to the game save folder.
save_path_full = std::string(getAppdataDirectory()) + std::string(LOVE_PATH_SEPARATOR);
save_path_full = std::string(getAppdataDirectory()) + std::string(PATH_SEPARATOR);
save_path_full += save_path_relative;
std::cout << save_path_full << std::endl;
@@ -155,7 +155,7 @@ namespace physfs
const char * Filesystem::getWorkingDirectory()
{
#ifdef LOVE_WINDOWS
#ifdef WINDOWS
_getcwd(cwdbuffer, _MAX_PATH);
#else
char * temp = getcwd(cwdbuffer, MAXPATHLEN);
@@ -172,7 +172,7 @@ namespace physfs
const char * Filesystem::getAppdataDirectory()
{
#ifdef LOVE_WINDOWS
#ifdef WINDOWS
return getenv("APPDATA");
#else
return getUserDirectory();
@@ -372,7 +372,7 @@ namespace physfs
return luaL_error(L, "Could not open file %s.\n", lua_tostring(L, 1));
lua_pop(L, 1);
luax_newtype(L, "File", LOVE_FILESYSTEM_FILE_BITS, file, false);
luax_newtype(L, "File", FILESYSTEM_FILE_T, file, false);
lua_pushboolean(L, 1); // 1 = autoclose.
}
else
@@ -392,7 +392,7 @@ namespace physfs
const static int bufsize = 8;
static char buf[bufsize];
File * file = luax_checktype<File>(L, lua_upvalueindex(1), "File", LOVE_FILESYSTEM_FILE_BITS);
File * file = luax_checktype<File>(L, lua_upvalueindex(1), "File", FILESYSTEM_FILE_T);
int close = (int)lua_tointeger(L, lua_upvalueindex(2));
// Find the next newline.
+28 -29
View File
@@ -28,17 +28,17 @@ namespace physfs
{
File * luax_checkfile(lua_State * L, int idx)
{
return luax_checktype<File>(L, idx, "File", LOVE_FILESYSTEM_FILE_BITS);
return luax_checktype<File>(L, idx, "File", FILESYSTEM_FILE_T);
}
int _wrap_File_getSize(lua_State * L)
int w_File_getSize(lua_State * L)
{
File * t = luax_checkfile(L, 1);
lua_pushinteger(L, t->getSize());
return 1;
}
int _wrap_File_open(lua_State * L)
int w_File_open(lua_State * L)
{
File * file = luax_checkfile(L, 1);
int mode = luaL_optint(L, 2, File::READ);
@@ -46,14 +46,14 @@ namespace physfs
return 1;
}
int _wrap_File_close(lua_State * L)
int w_File_close(lua_State * L)
{
File * file = luax_checkfile(L, 1);
lua_pushboolean(L, file->close() ? 1 : 0);
return 1;
}
int _wrap_File_read(lua_State * L)
int w_File_read(lua_State * L)
{
File * file = luax_checkfile(L, 1);
Data * d = file->read(luaL_optint(L, 2, file->getSize()));
@@ -63,7 +63,7 @@ namespace physfs
return 2;
}
int _wrap_File_write(lua_State * L)
int w_File_write(lua_State * L)
{
File * file = luax_checkfile(L, 1);
bool result;
@@ -77,21 +77,21 @@ namespace physfs
return 1;
}
int _wrap_File_eof(lua_State * L)
int w_File_eof(lua_State * L)
{
File * file = luax_checkfile(L, 1);
lua_pushboolean(L, file->eof() ? 1 : 0);
return 1;
}
int _wrap_File_tell(lua_State * L)
int w_File_tell(lua_State * L)
{
File * file = luax_checkfile(L, 1);
lua_pushinteger(L, file->tell());
return 1;
}
int _wrap_File_seek(lua_State * L)
int w_File_seek(lua_State * L)
{
File * file = luax_checkfile(L, 1);
int pos = luaL_checkinteger(L, 2);
@@ -101,13 +101,13 @@ namespace physfs
//yes, the following two are copy-pasted and slightly edited
int _wrap_File_lines(lua_State * L)
int w_File_lines(lua_State * L)
{
File * file;
if(luax_istype(L, 1, LOVE_FILESYSTEM_FILE_BITS))
if(luax_istype(L, 1, FILESYSTEM_FILE_T))
{
file = luax_checktype<File>(L, 1, "File", LOVE_FILESYSTEM_FILE_BITS);
file = luax_checktype<File>(L, 1, "File", FILESYSTEM_FILE_T);
lua_pushboolean(L, 0); // 0 = do not close.
}
else
@@ -127,7 +127,7 @@ namespace physfs
const static int bufsize = 1024;
static char buf[bufsize];
File * file = luax_checktype<File>(L, lua_upvalueindex(1), "File", LOVE_FILESYSTEM_FILE_BITS);
File * file = luax_checktype<File>(L, lua_upvalueindex(1), "File", FILESYSTEM_FILE_T);
int close = (int)lua_tointeger(L, lua_upvalueindex(2));
// Find the next newline.
@@ -201,23 +201,22 @@ namespace physfs
return 0;
}
const luaL_Reg wrap_File_functions[] = {
{ "getSize", _wrap_File_getSize },
{ "open", _wrap_File_open },
{ "close", _wrap_File_close },
{ "read", _wrap_File_read },
{ "write", _wrap_File_write },
{ "eof", _wrap_File_eof },
{ "tell", _wrap_File_tell },
{ "seek", _wrap_File_seek },
{ "lines", _wrap_File_lines },
{ 0, 0 }
};
int wrap_File_open(lua_State * L)
int luaopen_file(lua_State * L)
{
luax_register_type(L, "File", wrap_File_functions);
return 0;
static const luaL_Reg functions[] = {
{ "getSize", w_File_getSize },
{ "open", w_File_open },
{ "close", w_File_close },
{ "read", w_File_read },
{ "write", w_File_write },
{ "eof", w_File_eof },
{ "tell", w_File_tell },
{ "seek", w_File_seek },
{ "lines", w_File_lines },
{ 0, 0 }
};
return luax_register_type(L, "File", functions);
}
} // physfs
+10 -10
View File
@@ -32,17 +32,17 @@ namespace filesystem
namespace physfs
{
File * luax_checkfile(lua_State * L, int idx);
int _wrap_File_getSize(lua_State * L);
int _wrap_File_open(lua_State * L);
int _wrap_File_close(lua_State * L);
int _wrap_File_read(lua_State * L);
int _wrap_File_write(lua_State * L);
int _wrap_File_eof(lua_State * L);
int _wrap_File_tell(lua_State * L);
int _wrap_File_seek(lua_State * L);
int _wrap_File_lines(lua_State * L);
int w_File_getSize(lua_State * L);
int w_File_open(lua_State * L);
int w_File_close(lua_State * L);
int w_File_read(lua_State * L);
int w_File_write(lua_State * L);
int w_File_eof(lua_State * L);
int w_File_tell(lua_State * L);
int w_File_seek(lua_State * L);
int w_File_lines(lua_State * L);
int lines_i(lua_State * L);
int wrap_File_open(lua_State * L);
int luaopen_file(lua_State * L);
} // physfs
} // filesystem
} // love
+17 -18
View File
@@ -30,39 +30,38 @@ namespace physfs
{
FileData * luax_checkfiledata(lua_State * L, int idx)
{
return luax_checktype<FileData>(L, idx, "FileData", LOVE_FILESYSTEM_FILE_DATA_BITS);
return luax_checktype<FileData>(L, idx, "FileData", FILESYSTEM_FILE_DATA_T);
}
int _wrap_FileData_getFilename(lua_State * L)
int w_FileData_getFilename(lua_State * L)
{
FileData * t = luax_checkfiledata(L, 1);
lua_pushstring(L, t->getFilename().c_str());
return 1;
}
int _wrap_FileData_getExtension(lua_State * L)
int w_FileData_getExtension(lua_State * L)
{
FileData * t = luax_checkfiledata(L, 1);
lua_pushstring(L, t->getExtension().c_str());
return 1;
}
const luaL_Reg wrap_FileData_functions[] = {
// Data
{ "getPointer", _wrap_Data_getPointer },
{ "getSize", _wrap_Data_getSize },
{ "getFilename", _wrap_FileData_getFilename },
{ "getExtension", _wrap_FileData_getExtension },
{ 0, 0 }
};
int wrap_FileData_open(lua_State * L)
int w_FileData_open(lua_State * L)
{
luax_register_type(L, "FileData", wrap_FileData_functions);
return 0;
static const luaL_Reg w_FileData_functions[] = {
// Data
{ "getPointer", w_Data_getPointer },
{ "getSize", w_Data_getSize },
{ "getFilename", w_FileData_getFilename },
{ "getExtension", w_FileData_getExtension },
{ 0, 0 }
};
return luax_register_type(L, "FileData", w_FileData_functions);
}
} // physfs
@@ -33,9 +33,9 @@ namespace filesystem
namespace physfs
{
FileData * luax_checkfiledata(lua_State * L, int idx);
int _wrap_FileData_getFilename(lua_State * L);
int _wrap_FileData_getExtension(lua_State * L);
int wrap_FileData_open(lua_State * L);
int w_FileData_getFilename(lua_State * L);
int w_FileData_getExtension(lua_State * L);
int w_FileData_open(lua_State * L);
} // physfs
} // filesystem
} // love
@@ -36,7 +36,7 @@ namespace physfs
return false;
}
int _wrap_init(lua_State * L)
int w_init(lua_State * L)
{
const char * arg0 = luaL_checkstring(L, 1);
@@ -52,7 +52,7 @@ namespace physfs
return 0;
}
int _wrap_setIdentity(lua_State * L)
int w_setIdentity(lua_State * L)
{
const char * arg = luaL_checkstring(L, 1);
@@ -62,7 +62,7 @@ namespace physfs
return 0;
}
int _wrap_setSource(lua_State * L)
int w_setSource(lua_State * L)
{
const char * arg = luaL_checkstring(L, 1);
@@ -72,15 +72,15 @@ namespace physfs
return 0;
}
int _wrap_newFile(lua_State * L)
int w_newFile(lua_State * L)
{
const char * filename = luaL_checkstring(L, 1);
File * t = instance->newFile(filename);
luax_newtype(L, "File", LOVE_FILESYSTEM_FILE_BITS, (void*)t);
luax_newtype(L, "File", FILESYSTEM_FILE_T, (void*)t);
return 1;
}
int _wrap_newFileData(lua_State * L)
int w_newFileData(lua_State * L)
{
if(!lua_isstring(L, 1))
return luaL_error(L, "String expected.");
@@ -93,90 +93,90 @@ namespace physfs
FileData * t = instance->newFileData((void*)str, (int)length, filename);
luax_newtype(L, "FileData", LOVE_FILESYSTEM_FILE_DATA_BITS, (void*)t);
luax_newtype(L, "FileData", FILESYSTEM_FILE_DATA_T, (void*)t);
return 1;
}
int _wrap_getWorkingDirectory(lua_State * L)
int w_getWorkingDirectory(lua_State * L)
{
lua_pushstring(L, instance->getWorkingDirectory());
return 1;
}
int _wrap_getUserDirectory(lua_State * L)
int w_getUserDirectory(lua_State * L)
{
lua_pushstring(L, instance->getUserDirectory());
return 1;
}
int _wrap_getAppdataDirectory(lua_State * L)
int w_getAppdataDirectory(lua_State * L)
{
lua_pushstring(L, instance->getAppdataDirectory());
return 1;
}
int _wrap_getSaveDirectory(lua_State * L)
int w_getSaveDirectory(lua_State * L)
{
lua_pushstring(L, instance->getSaveDirectory());
return 1;
}
int _wrap_exists(lua_State * L)
int w_exists(lua_State * L)
{
const char * arg = luaL_checkstring(L, 1);
lua_pushboolean(L, instance->exists(arg) ? 1 : 0);
return 1;
}
int _wrap_isDirectory(lua_State * L)
int w_isDirectory(lua_State * L)
{
const char * arg = luaL_checkstring(L, 1);
lua_pushboolean(L, instance->isDirectory(arg) ? 1 : 0);
return 1;
}
int _wrap_isFile(lua_State * L)
int w_isFile(lua_State * L)
{
const char * arg = luaL_checkstring(L, 1);
lua_pushboolean(L, instance->isFile(arg) ? 1 : 0);
return 1;
}
int _wrap_mkdir(lua_State * L)
int w_mkdir(lua_State * L)
{
const char * arg = luaL_checkstring(L, 1);
lua_pushboolean(L, instance->mkdir(arg) ? 1 : 0);
return 1;
}
int _wrap_remove(lua_State * L)
int w_remove(lua_State * L)
{
const char * arg = luaL_checkstring(L, 1);
lua_pushboolean(L, instance->remove(arg) ? 1 : 0);
return 1;
}
int _wrap_read(lua_State * L)
int w_read(lua_State * L)
{
return instance->read(L);
}
int _wrap_write(lua_State * L)
int w_write(lua_State * L)
{
return instance->write(L);
}
int _wrap_enumerate(lua_State * L)
int w_enumerate(lua_State * L)
{
return instance->enumerate(L);
}
int _wrap_lines(lua_State * L)
int w_lines(lua_State * L)
{
return instance->lines(L);
}
int _wrap_load(lua_State * L)
int w_load(lua_State * L)
{
return instance->load(L);
}
@@ -214,46 +214,46 @@ namespace physfs
return instance->load(L);
}
// List of functions to wrap.
const luaL_Reg wrap_Filesystem_functions[] = {
{ "init", _wrap_init },
{ "setIdentity", _wrap_setIdentity },
{ "setSource", _wrap_setSource },
{ "newFile", _wrap_newFile },
{ "getWorkingDirectory", _wrap_getWorkingDirectory },
{ "getUserDirectory", _wrap_getUserDirectory },
{ "getAppdataDirectory", _wrap_getAppdataDirectory },
{ "getSaveDirectory", _wrap_getSaveDirectory },
{ "exists", _wrap_exists },
{ "isDirectory", _wrap_isDirectory },
{ "isFile", _wrap_isFile },
{ "mkdir", _wrap_mkdir },
{ "remove", _wrap_remove },
{ "read", _wrap_read },
{ "write", _wrap_write },
{ "enumerate", _wrap_enumerate },
{ "lines", _wrap_lines },
{ "load", _wrap_load },
{ 0, 0 }
};
const lua_CFunction wrap_Filesystem_types[] = {
wrap_File_open,
wrap_FileData_open,
0
};
// List of constants.
static const LuaConstant wrap_Filesystem_constants[] = {
{ "file_closed", File::CLOSED },
{ "file_read", File::READ },
{ "file_write", File::WRITE },
{ "file_append", File::APPEND },
{ 0, 0 }
};
int wrap_Filesystem_open(lua_State * L)
int w_Filesystem_open(lua_State * L)
{
// List of functions to wrap.
static const luaL_Reg functions[] = {
{ "init", w_init },
{ "setIdentity", w_setIdentity },
{ "setSource", w_setSource },
{ "newFile", w_newFile },
{ "getWorkingDirectory", w_getWorkingDirectory },
{ "getUserDirectory", w_getUserDirectory },
{ "getAppdataDirectory", w_getAppdataDirectory },
{ "getSaveDirectory", w_getSaveDirectory },
{ "exists", w_exists },
{ "isDirectory", w_isDirectory },
{ "isFile", w_isFile },
{ "mkdir", w_mkdir },
{ "remove", w_remove },
{ "read", w_read },
{ "write", w_write },
{ "enumerate", w_enumerate },
{ "lines", w_lines },
{ "load", w_load },
{ 0, 0 }
};
static const lua_CFunction types[] = {
luaopen_file,
luaopen_filedata,
0
};
// List of constants.
static const LuaConstant constants[] = {
{ "file_closed", File::CLOSED },
{ "file_read", File::READ },
{ "file_write", File::WRITE },
{ "file_append", File::APPEND },
{ 0, 0 }
};
if(instance == 0)
{
try
@@ -267,16 +267,11 @@ namespace physfs
}
}
luax_register_gc(L, "love.filesystem", instance);
luax_register_gc(L, instance);
return luax_register_module(L, wrap_Filesystem_functions, wrap_Filesystem_types, wrap_Filesystem_constants, "filesystem");
return luax_register_module(L, functions, types, constants, "filesystem");
}
} // physfs
} // filesystem
} // love
int luaopen_love_filesystem(lua_State * L)
{
return love::filesystem::physfs::wrap_Filesystem_open(L);
}
} // love
+25 -27
View File
@@ -33,37 +33,35 @@ namespace filesystem
namespace physfs
{
bool hack_setupWriteDirectory();
int _wrap_init(lua_State * L);
int _wrap_setIdentity(lua_State * L);
int _wrap_setSource(lua_State * L);
int _wrap_newFile(lua_State * L);
int _wrap_newFileData(lua_State * L);
int _wrap_getWorkingDirectory(lua_State * L);
int _wrap_getUserDirectory(lua_State * L);
int _wrap_getAppdataDirectory(lua_State * L);
int _wrap_getSaveDirectory(lua_State * L);
int _wrap_exists(lua_State * L);
int _wrap_isDirectory(lua_State * L);
int _wrap_isFile(lua_State * L);
int _wrap_mkdir(lua_State * L);
int _wrap_remove(lua_State * L);
int _wrap_open(lua_State * L);
int _wrap_close(lua_State * L);
int _wrap_read(lua_State * L);
int _wrap_write(lua_State * L);
int _wrap_eof(lua_State * L);
int _wrap_tell(lua_State * L);
int _wrap_seek(lua_State * L);
int _wrap_enumerate(lua_State * L);
int _wrap_lines(lua_State * L);
int _wrap_load(lua_State * L);
int w_init(lua_State * L);
int w_setIdentity(lua_State * L);
int w_setSource(lua_State * L);
int w_newFile(lua_State * L);
int w_newFileData(lua_State * L);
int w_getWorkingDirectory(lua_State * L);
int w_getUserDirectory(lua_State * L);
int w_getAppdataDirectory(lua_State * L);
int w_getSaveDirectory(lua_State * L);
int w_exists(lua_State * L);
int w_isDirectory(lua_State * L);
int w_isFile(lua_State * L);
int w_mkdir(lua_State * L);
int w_remove(lua_State * L);
int w_open(lua_State * L);
int w_close(lua_State * L);
int w_read(lua_State * L);
int w_write(lua_State * L);
int w_eof(lua_State * L);
int w_tell(lua_State * L);
int w_seek(lua_State * L);
int w_enumerate(lua_State * L);
int w_lines(lua_State * L);
int w_load(lua_State * L);
int loader(lua_State * L);
int wrap_Filesystem_open(lua_State * L);
extern "C" LOVE_EXPORT int luaopen_love_filesystem(lua_State * L);
} // physfs
} // filesystem
} // love
extern "C" LOVE_EXPORT int luaopen_love_filesystem(lua_State * L);
#endif // LOVE_FILESYSTEM_PHYSFS_WRAP_FILESYSTEM_H