From bc9e030722ff39485b309a5bdbb63a753970db3c Mon Sep 17 00:00:00 2001 From: Vecais Dumais Laacis Date: Sun, 11 Mar 2007 21:24:50 +0000 Subject: [PATCH] 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(); --- stepmania/src/RageFile.cpp | 82 ++++++++++++++++++++++++++++++++++++++ stepmania/src/RageFile.h | 3 ++ 2 files changed, 85 insertions(+) diff --git a/stepmania/src/RageFile.cpp b/stepmania/src/RageFile.cpp index fca23cb224..25034968d8 100644 --- a/stepmania/src/RageFile.cpp +++ b/stepmania/src/RageFile.cpp @@ -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 +{ +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. diff --git a/stepmania/src/RageFile.h b/stepmania/src/RageFile.h index d340332f82..10351778d8 100644 --- a/stepmania/src/RageFile.h +++ b/stepmania/src/RageFile.h @@ -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 );