really thin Lua wrapper for RageFile
maybe not the best way but so far thats only one i could find which works
usage:
local f = RageFileUtil.CreateRageFile();
if f:Open("test.txt", 2) then -- 2 means write, 1 - read (from RageFile.h) maybe those need some lua enum?
f:PutLine("test text line");
f:Close();
end;
f:destroy();
This commit is contained in:
@@ -302,6 +302,88 @@ int32_t FileReading::read_32_le( RageFileBasic &f, RString &sError )
|
||||
return 0;
|
||||
}
|
||||
|
||||
// lua start
|
||||
#include "LuaBinding.h"
|
||||
|
||||
class LunaRageFile: public Luna<RageFile>
|
||||
{
|
||||
public:
|
||||
static int destroy( T* p, lua_State *L )
|
||||
{
|
||||
SAFE_DELETE(p);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int Open( T* p, lua_State *L )
|
||||
{
|
||||
lua_pushboolean( L, p->Open( SArg(1), IArg(2) ) );
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int Close( T* p, lua_State *L )
|
||||
{
|
||||
p->Close();
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int Write( T* p, lua_State *L )
|
||||
{
|
||||
lua_pushinteger( L, p->Write( SArg(1) ) );
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int Read( T* p, lua_State *L )
|
||||
{
|
||||
RString string;
|
||||
p->Read(string);
|
||||
lua_pushstring( L, string );
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int GetLine( T* p, lua_State *L )
|
||||
{
|
||||
RString string;
|
||||
p->GetLine(string);
|
||||
lua_pushstring( L, string );
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int PutLine( T* p, lua_State *L )
|
||||
{
|
||||
lua_pushinteger( L, p->PutLine( SArg(1) ) );
|
||||
return 1;
|
||||
}
|
||||
|
||||
LunaRageFile()
|
||||
{
|
||||
ADD_METHOD( Open );
|
||||
ADD_METHOD( Close );
|
||||
ADD_METHOD( Write );
|
||||
ADD_METHOD( Read );
|
||||
ADD_METHOD( GetLine );
|
||||
ADD_METHOD( PutLine );
|
||||
ADD_METHOD( destroy );
|
||||
}
|
||||
};
|
||||
|
||||
LUA_REGISTER_CLASS( RageFile )
|
||||
|
||||
namespace RageFileUtil
|
||||
{
|
||||
int CreateRageFile( lua_State *L )
|
||||
{
|
||||
RageFile *pFile = new RageFile;
|
||||
pFile->PushSelf( L );
|
||||
return 1;
|
||||
}
|
||||
const luaL_Reg RageFileUtilTable[] =
|
||||
{
|
||||
LIST_METHOD( CreateRageFile ),
|
||||
{ NULL, NULL }
|
||||
};
|
||||
LUA_REGISTER_NAMESPACE( RageFileUtil );
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 2003-2004 Glenn Maynard, Chris Danford, Steve Checkoway
|
||||
* All rights reserved.
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#define RAGE_FILE_H
|
||||
|
||||
#include "RageFileBasic.h"
|
||||
struct lua_State;
|
||||
|
||||
/* This is the high-level interface, which interfaces with RageFileObj implementations
|
||||
* and RageFileManager. */
|
||||
@@ -70,6 +71,8 @@ public:
|
||||
void EnableCRC32( bool on=true );
|
||||
bool GetCRC32( uint32_t *iRet );
|
||||
|
||||
// Lua
|
||||
virtual void PushSelf( lua_State *L );
|
||||
private:
|
||||
void SetError( const RString &err );
|
||||
|
||||
|
||||
Reference in New Issue
Block a user