1
0

Added static cFile functions to Lua API.

This commit is contained in:
madmaxoft 2013-10-09 09:38:47 +02:00
parent 36f24e30b7
commit 2ff882f239
6 changed files with 320 additions and 16 deletions

View File

@ -17,6 +17,8 @@ $cfile "ChunkDef.h"
$cfile "../iniFile/iniFile.h" $cfile "../iniFile/iniFile.h"
$cfile "OSSupport/File.h"
$cfile "BlockID.h" $cfile "BlockID.h"
$cfile "StringUtils.h" $cfile "StringUtils.h"
$cfile "Defines.h" $cfile "Defines.h"

View File

@ -1,6 +1,6 @@
/* /*
** Lua binding: AllToLua ** 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 #ifndef __cplusplus
@ -17,6 +17,7 @@ TOLUA_API int tolua_AllToLua_open (lua_State* tolua_S);
#include "tolua_base.h" #include "tolua_base.h"
#include "ChunkDef.h" #include "ChunkDef.h"
#include "../iniFile/iniFile.h" #include "../iniFile/iniFile.h"
#include "OSSupport/File.h"
#include "BlockID.h" #include "BlockID.h"
#include "StringUtils.h" #include "StringUtils.h"
#include "Defines.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,"cInventory");
tolua_usertype(tolua_S,"cBoundingBox"); tolua_usertype(tolua_S,"cBoundingBox");
tolua_usertype(tolua_S,"cBlockEntityWithItems"); tolua_usertype(tolua_S,"cBlockEntityWithItems");
tolua_usertype(tolua_S,"cTracer");
tolua_usertype(tolua_S,"HTTPFormData");
tolua_usertype(tolua_S,"cWindow"); 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,"cArrowEntity");
tolua_usertype(tolua_S,"cDropSpenserEntity"); tolua_usertype(tolua_S,"cDropSpenserEntity");
tolua_usertype(tolua_S,"cBlockArea"); tolua_usertype(tolua_S,"cBlockArea");
tolua_usertype(tolua_S,"cCraftingGrid"); tolua_usertype(tolua_S,"cTracer");
tolua_usertype(tolua_S,"Vector3i");
tolua_usertype(tolua_S,"cGroup");
tolua_usertype(tolua_S,"cStringMap"); tolua_usertype(tolua_S,"cStringMap");
tolua_usertype(tolua_S,"cServer");
tolua_usertype(tolua_S,"Vector3i");
tolua_usertype(tolua_S,"cBlockEntity"); tolua_usertype(tolua_S,"cBlockEntity");
tolua_usertype(tolua_S,"cCriticalSection"); tolua_usertype(tolua_S,"cCriticalSection");
tolua_usertype(tolua_S,"HTTPTemplateRequest"); 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,"std::vector<std::string>");
tolua_usertype(tolua_S,"cClientHandle"); tolua_usertype(tolua_S,"cClientHandle");
tolua_usertype(tolua_S,"cChatColor"); tolua_usertype(tolua_S,"cChatColor");
tolua_usertype(tolua_S,"sWebAdminPage");
tolua_usertype(tolua_S,"cWebPlugin"); tolua_usertype(tolua_S,"cWebPlugin");
tolua_usertype(tolua_S,"cIniFile");
tolua_usertype(tolua_S,"cWebAdmin"); tolua_usertype(tolua_S,"cWebAdmin");
tolua_usertype(tolua_S,"cIniFile");
tolua_usertype(tolua_S,"sWebAdminPage");
tolua_usertype(tolua_S,"cItem"); tolua_usertype(tolua_S,"cItem");
tolua_usertype(tolua_S,"cPawn"); tolua_usertype(tolua_S,"cPawn");
tolua_usertype(tolua_S,"cPlayer"); tolua_usertype(tolua_S,"cPlayer");
@ -2461,6 +2463,229 @@ tolua_lerror:
} }
#endif //#ifndef TOLUA_DISABLE #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 */ /* function: BlockStringToType */
#ifndef TOLUA_DISABLE_tolua_AllToLua_BlockStringToType00 #ifndef TOLUA_DISABLE_tolua_AllToLua_BlockStringToType00
static int tolua_AllToLua_BlockStringToType00(lua_State* tolua_S) 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_DeleteKeyComments00);
tolua_function(tolua_S,"DeleteKeyComments",tolua_AllToLua_cIniFile_DeleteKeyComments01); tolua_function(tolua_S,"DeleteKeyComments",tolua_AllToLua_cIniFile_DeleteKeyComments01);
tolua_endmodule(tolua_S); 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_AIR",E_BLOCK_AIR);
tolua_constant(tolua_S,"E_BLOCK_STONE",E_BLOCK_STONE); tolua_constant(tolua_S,"E_BLOCK_STONE",E_BLOCK_STONE);
tolua_constant(tolua_S,"E_BLOCK_GRASS",E_BLOCK_GRASS); tolua_constant(tolua_S,"E_BLOCK_GRASS",E_BLOCK_GRASS);

View File

@ -1,6 +1,6 @@
/* /*
** Lua binding: AllToLua ** 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 */ /* Exported function */

View File

@ -109,7 +109,6 @@ typedef unsigned short UInt16;
#endif // GetFreeSpace #endif // GetFreeSpace
#else #else
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> // for mkdir
#include <sys/time.h> #include <sys/time.h>
#include <sys/socket.h> #include <sys/socket.h>
#include <netinet/in.h> #include <netinet/in.h>
@ -142,6 +141,7 @@ typedef unsigned short UInt16;
// CRT stuff: // CRT stuff:
#include <sys/stat.h>
#include <assert.h> #include <assert.h>
#include <stdio.h> #include <stdio.h>
#include <math.h> #include <math.h>

View File

@ -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) int cFile::Write(const void * iBuffer, int iNumBytes)
{ {
ASSERT(IsOpen()); 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) int cFile::Seek (int iPosition)
{ {
ASSERT(IsOpen()); ASSERT(IsOpen());
@ -191,7 +189,6 @@ int cFile::Seek (int iPosition)
/// Returns the current position (bytes from file start)
int cFile::Tell (void) const int cFile::Tell (void) const
{ {
ASSERT(IsOpen()); 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 int cFile::GetSize(void) const
{ {
ASSERT(IsOpen()); 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) bool cFile::IsFolder(const AString & a_Path)
{ {
#ifdef _WIN32 #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, ...) int cFile::Printf(const char * a_Fmt, ...)
{ {
AString buf; AString buf;

View File

@ -41,9 +41,14 @@ Usage:
// tolua_begin
class cFile class cFile
{ {
public: public:
// tolua_end
#ifdef _WIN32 #ifdef _WIN32
static const char PathSeparator = '\\'; static const char PathSeparator = '\\';
#else #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 /// 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); int ReadRestOfFile(AString & a_Contents);
// tolua_begin
/// Returns true if the file specified exists /// Returns true if the file specified exists
static bool Exists(const AString & a_FileName); 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)! /// 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); 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 /// Returns true if the specified path is a folder
static bool IsFolder(const AString & a_Path); 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, ...); int Printf(const char * a_Fmt, ...);
private: private:
@ -110,7 +128,7 @@ private:
#else #else
HANDLE m_File; HANDLE m_File;
#endif #endif
} ; } ; // tolua_export