summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--source/AllToLua.pkg2
-rw-r--r--source/Bindings.cpp253
-rw-r--r--source/Bindings.h2
-rw-r--r--source/Globals.h2
-rw-r--r--source/OSSupport/File.cpp57
-rw-r--r--source/OSSupport/File.h20
6 files changed, 320 insertions, 16 deletions
diff --git a/source/AllToLua.pkg b/source/AllToLua.pkg
index b423c43a5..00257e460 100644
--- a/source/AllToLua.pkg
+++ b/source/AllToLua.pkg
@@ -17,6 +17,8 @@ $cfile "ChunkDef.h"
$cfile "../iniFile/iniFile.h"
+$cfile "OSSupport/File.h"
+
$cfile "BlockID.h"
$cfile "StringUtils.h"
$cfile "Defines.h"
diff --git a/source/Bindings.cpp b/source/Bindings.cpp
index 48d8f3f83..c4467eab4 100644
--- a/source/Bindings.cpp
+++ b/source/Bindings.cpp
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 10/08/13 20:07:51.
+** Generated automatically by tolua++-1.0.92 on 10/09/13 09:38:09.
*/
#ifndef __cplusplus
@@ -17,6 +17,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S);
#include "tolua_base.h"
#include "ChunkDef.h"
#include "../iniFile/iniFile.h"
+#include "OSSupport/File.h"
#include "BlockID.h"
#include "StringUtils.h"
#include "Defines.h"
@@ -245,27 +246,28 @@ static void tolua_reg_types (lua_State* tolua_S)
tolua_usertype(tolua_S,"cInventory");
tolua_usertype(tolua_S,"cBoundingBox");
tolua_usertype(tolua_S,"cBlockEntityWithItems");
- tolua_usertype(tolua_S,"cTracer");
- tolua_usertype(tolua_S,"HTTPFormData");
tolua_usertype(tolua_S,"cWindow");
+ tolua_usertype(tolua_S,"cGroup");
+ tolua_usertype(tolua_S,"HTTPFormData");
+ tolua_usertype(tolua_S,"cCraftingGrid");
tolua_usertype(tolua_S,"cArrowEntity");
tolua_usertype(tolua_S,"cDropSpenserEntity");
tolua_usertype(tolua_S,"cBlockArea");
- tolua_usertype(tolua_S,"cCraftingGrid");
- tolua_usertype(tolua_S,"Vector3i");
- tolua_usertype(tolua_S,"cGroup");
+ tolua_usertype(tolua_S,"cTracer");
tolua_usertype(tolua_S,"cStringMap");
+ tolua_usertype(tolua_S,"cServer");
+ tolua_usertype(tolua_S,"Vector3i");
tolua_usertype(tolua_S,"cBlockEntity");
tolua_usertype(tolua_S,"cCriticalSection");
tolua_usertype(tolua_S,"HTTPTemplateRequest");
- tolua_usertype(tolua_S,"cServer");
+ tolua_usertype(tolua_S,"cFile");
tolua_usertype(tolua_S,"std::vector<std::string>");
tolua_usertype(tolua_S,"cClientHandle");
tolua_usertype(tolua_S,"cChatColor");
- tolua_usertype(tolua_S,"sWebAdminPage");
tolua_usertype(tolua_S,"cWebPlugin");
- tolua_usertype(tolua_S,"cIniFile");
tolua_usertype(tolua_S,"cWebAdmin");
+ tolua_usertype(tolua_S,"cIniFile");
+ tolua_usertype(tolua_S,"sWebAdminPage");
tolua_usertype(tolua_S,"cItem");
tolua_usertype(tolua_S,"cPawn");
tolua_usertype(tolua_S,"cPlayer");
@@ -2461,6 +2463,229 @@ tolua_lerror:
}
#endif //#ifndef TOLUA_DISABLE
+/* method: Exists of class cFile */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cFile_Exists00
+static int tolua_AllToLua_cFile_Exists00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertable(tolua_S,1,"cFile",0,&tolua_err) ||
+ !tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ const AString a_FileName = ((const AString) tolua_tocppstring(tolua_S,2,0));
+ {
+ bool tolua_ret = (bool) cFile::Exists(a_FileName);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ tolua_pushcppstring(tolua_S,(const char*)a_FileName);
+ }
+ }
+ return 2;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'Exists'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: Delete of class cFile */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cFile_Delete00
+static int tolua_AllToLua_cFile_Delete00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertable(tolua_S,1,"cFile",0,&tolua_err) ||
+ !tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ const AString a_FileName = ((const AString) tolua_tocppstring(tolua_S,2,0));
+ {
+ bool tolua_ret = (bool) cFile::Delete(a_FileName);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ tolua_pushcppstring(tolua_S,(const char*)a_FileName);
+ }
+ }
+ return 2;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'Delete'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: Rename of class cFile */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cFile_Rename00
+static int tolua_AllToLua_cFile_Rename00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertable(tolua_S,1,"cFile",0,&tolua_err) ||
+ !tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
+ !tolua_iscppstring(tolua_S,3,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,4,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ const AString a_OrigFileName = ((const AString) tolua_tocppstring(tolua_S,2,0));
+ const AString a_NewFileName = ((const AString) tolua_tocppstring(tolua_S,3,0));
+ {
+ bool tolua_ret = (bool) cFile::Rename(a_OrigFileName,a_NewFileName);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ tolua_pushcppstring(tolua_S,(const char*)a_OrigFileName);
+ tolua_pushcppstring(tolua_S,(const char*)a_NewFileName);
+ }
+ }
+ return 3;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'Rename'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: Copy of class cFile */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cFile_Copy00
+static int tolua_AllToLua_cFile_Copy00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertable(tolua_S,1,"cFile",0,&tolua_err) ||
+ !tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
+ !tolua_iscppstring(tolua_S,3,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,4,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ const AString a_SrcFileName = ((const AString) tolua_tocppstring(tolua_S,2,0));
+ const AString a_DstFileName = ((const AString) tolua_tocppstring(tolua_S,3,0));
+ {
+ bool tolua_ret = (bool) cFile::Copy(a_SrcFileName,a_DstFileName);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ tolua_pushcppstring(tolua_S,(const char*)a_SrcFileName);
+ tolua_pushcppstring(tolua_S,(const char*)a_DstFileName);
+ }
+ }
+ return 3;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'Copy'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: IsFolder of class cFile */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cFile_IsFolder00
+static int tolua_AllToLua_cFile_IsFolder00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertable(tolua_S,1,"cFile",0,&tolua_err) ||
+ !tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ const AString a_Path = ((const AString) tolua_tocppstring(tolua_S,2,0));
+ {
+ bool tolua_ret = (bool) cFile::IsFolder(a_Path);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ tolua_pushcppstring(tolua_S,(const char*)a_Path);
+ }
+ }
+ return 2;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'IsFolder'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: IsFile of class cFile */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cFile_IsFile00
+static int tolua_AllToLua_cFile_IsFile00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertable(tolua_S,1,"cFile",0,&tolua_err) ||
+ !tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ const AString a_Path = ((const AString) tolua_tocppstring(tolua_S,2,0));
+ {
+ bool tolua_ret = (bool) cFile::IsFile(a_Path);
+ tolua_pushboolean(tolua_S,(bool)tolua_ret);
+ tolua_pushcppstring(tolua_S,(const char*)a_Path);
+ }
+ }
+ return 2;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'IsFile'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
+/* method: GetSize of class cFile */
+#ifndef TOLUA_DISABLE_tolua_AllToLua_cFile_GetSize00
+static int tolua_AllToLua_cFile_GetSize00(lua_State* tolua_S)
+{
+#ifndef TOLUA_RELEASE
+ tolua_Error tolua_err;
+ if (
+ !tolua_isusertable(tolua_S,1,"cFile",0,&tolua_err) ||
+ !tolua_iscppstring(tolua_S,2,0,&tolua_err) ||
+ !tolua_isnoobj(tolua_S,3,&tolua_err)
+ )
+ goto tolua_lerror;
+ else
+#endif
+ {
+ const AString a_FileName = ((const AString) tolua_tocppstring(tolua_S,2,0));
+ {
+ int tolua_ret = (int) cFile::GetSize(a_FileName);
+ tolua_pushnumber(tolua_S,(lua_Number)tolua_ret);
+ tolua_pushcppstring(tolua_S,(const char*)a_FileName);
+ }
+ }
+ return 2;
+#ifndef TOLUA_RELEASE
+ tolua_lerror:
+ tolua_error(tolua_S,"#ferror in function 'GetSize'.",&tolua_err);
+ return 0;
+#endif
+}
+#endif //#ifndef TOLUA_DISABLE
+
/* function: BlockStringToType */
#ifndef TOLUA_DISABLE_tolua_AllToLua_BlockStringToType00
static int tolua_AllToLua_BlockStringToType00(lua_State* tolua_S)
@@ -28906,6 +29131,16 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S)
tolua_function(tolua_S,"DeleteKeyComments",tolua_AllToLua_cIniFile_DeleteKeyComments00);
tolua_function(tolua_S,"DeleteKeyComments",tolua_AllToLua_cIniFile_DeleteKeyComments01);
tolua_endmodule(tolua_S);
+ tolua_cclass(tolua_S,"cFile","cFile","",NULL);
+ tolua_beginmodule(tolua_S,"cFile");
+ tolua_function(tolua_S,"Exists",tolua_AllToLua_cFile_Exists00);
+ tolua_function(tolua_S,"Delete",tolua_AllToLua_cFile_Delete00);
+ tolua_function(tolua_S,"Rename",tolua_AllToLua_cFile_Rename00);
+ tolua_function(tolua_S,"Copy",tolua_AllToLua_cFile_Copy00);
+ tolua_function(tolua_S,"IsFolder",tolua_AllToLua_cFile_IsFolder00);
+ tolua_function(tolua_S,"IsFile",tolua_AllToLua_cFile_IsFile00);
+ tolua_function(tolua_S,"GetSize",tolua_AllToLua_cFile_GetSize00);
+ tolua_endmodule(tolua_S);
tolua_constant(tolua_S,"E_BLOCK_AIR",E_BLOCK_AIR);
tolua_constant(tolua_S,"E_BLOCK_STONE",E_BLOCK_STONE);
tolua_constant(tolua_S,"E_BLOCK_GRASS",E_BLOCK_GRASS);
diff --git a/source/Bindings.h b/source/Bindings.h
index a1daea398..6a5347506 100644
--- a/source/Bindings.h
+++ b/source/Bindings.h
@@ -1,6 +1,6 @@
/*
** Lua binding: AllToLua
-** Generated automatically by tolua++-1.0.92 on 10/08/13 20:07:52.
+** Generated automatically by tolua++-1.0.92 on 10/09/13 09:38:10.
*/
/* Exported function */
diff --git a/source/Globals.h b/source/Globals.h
index 150051de0..1e531f7f3 100644
--- a/source/Globals.h
+++ b/source/Globals.h
@@ -109,7 +109,6 @@ typedef unsigned short UInt16;
#endif // GetFreeSpace
#else
#include <sys/types.h>
- #include <sys/stat.h> // for mkdir
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h>
@@ -142,6 +141,7 @@ typedef unsigned short UInt16;
// CRT stuff:
+#include <sys/stat.h>
#include <assert.h>
#include <stdio.h>
#include <math.h>
diff --git a/source/OSSupport/File.cpp b/source/OSSupport/File.cpp
index a4c9a22f4..16ec00e16 100644
--- a/source/OSSupport/File.cpp
+++ b/source/OSSupport/File.cpp
@@ -151,7 +151,6 @@ int cFile::Read (void * iBuffer, int iNumBytes)
-/// Writes up to iNumBytes bytes from iBuffer, returns the number of bytes actually written, or -1 on failure; asserts if not open
int cFile::Write(const void * iBuffer, int iNumBytes)
{
ASSERT(IsOpen());
@@ -169,7 +168,6 @@ int cFile::Write(const void * iBuffer, int iNumBytes)
-/// Seeks to iPosition bytes from file start, returns old position or -1 for failure
int cFile::Seek (int iPosition)
{
ASSERT(IsOpen());
@@ -191,7 +189,6 @@ int cFile::Seek (int iPosition)
-/// Returns the current position (bytes from file start)
int cFile::Tell (void) const
{
ASSERT(IsOpen());
@@ -208,7 +205,6 @@ int cFile::Tell (void) const
-/// Returns the size of file, in bytes, or -1 for failure; asserts if not open
int cFile::GetSize(void) const
{
ASSERT(IsOpen());
@@ -287,6 +283,30 @@ bool cFile::Rename(const AString & a_OrigFileName, const AString & a_NewFileName
+bool cFile::Copy(const AString & a_SrcFileName, const AString & a_DstFileName)
+{
+ #ifdef _WIN32
+ return (CopyFile(a_SrcFileName.c_str(), a_DstFileName.c_str(), true) != 0);
+ #else
+ // Other OSs don't have a direct CopyFile equivalent, do it the harder way:
+ ifstream src(a_SrcFileName, ios::binary);
+ ofstream dst(a_DstFileName, ios::binary);
+ if (dst.good())
+ {
+ dst << src.rdbuf();
+ return true;
+ }
+ else
+ {
+ return false;
+ }
+ #endif
+}
+
+
+
+
+
bool cFile::IsFolder(const AString & a_Path)
{
#ifdef _WIN32
@@ -302,6 +322,35 @@ bool cFile::IsFolder(const AString & a_Path)
+bool cFile::IsFile(const AString & a_Path)
+{
+ #ifdef _WIN32
+ DWORD FileAttrib = GetFileAttributes(a_Path.c_str());
+ return ((FileAttrib != INVALID_FILE_ATTRIBUTES) && ((FileAttrib & (FILE_ATTRIBUTE_DIRECTORY | FILE_ATTRIBUTE_DEVICE)) == 0));
+ #else
+ struct stat st;
+ return ((stat(a_Path.c_str(), &st) == 0) && S_ISREG(st.st_mode));
+ #endif
+}
+
+
+
+
+
+int cFile::GetSize(const AString & a_FileName)
+{
+ struct stat st;
+ if (stat(a_FileName.c_str(), &st) == 0)
+ {
+ return st.st_size;
+ }
+ return -1;
+}
+
+
+
+
+
int cFile::Printf(const char * a_Fmt, ...)
{
AString buf;
diff --git a/source/OSSupport/File.h b/source/OSSupport/File.h
index d4ea0d3a8..f47bd4041 100644
--- a/source/OSSupport/File.h
+++ b/source/OSSupport/File.h
@@ -41,9 +41,14 @@ Usage:
+// tolua_begin
+
class cFile
{
public:
+
+ // tolua_end
+
#ifdef _WIN32
static const char PathSeparator = '\\';
#else
@@ -90,6 +95,8 @@ public:
/// Reads the file from current position till EOF into an AString; returns the number of bytes read or -1 for error
int ReadRestOfFile(AString & a_Contents);
+ // tolua_begin
+
/// Returns true if the file specified exists
static bool Exists(const AString & a_FileName);
@@ -99,9 +106,20 @@ public:
/// Renames a file, returns true if successful. May fail if dest already exists (libc-dependant)!
static bool Rename(const AString & a_OrigFileName, const AString & a_NewFileName);
+ /// Copies a file, returns true if successful.
+ static bool Copy(const AString & a_SrcFileName, const AString & a_DstFileName);
+
/// Returns true if the specified path is a folder
static bool IsFolder(const AString & a_Path);
+ /// Returns true if the specified path is a regular file
+ static bool IsFile(const AString & a_Path);
+
+ /// Returns the size of the file, or a negative number on error
+ static int GetSize(const AString & a_FileName);
+
+ // tolua_end
+
int Printf(const char * a_Fmt, ...);
private:
@@ -110,7 +128,7 @@ private:
#else
HANDLE m_File;
#endif
-} ;
+} ; // tolua_export