From 105e01232ac011c6123e245c21b6b91f4977f5ab Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Tue, 22 Feb 2005 23:06:51 +0000 Subject: [PATCH] add Lua bindings --- stepmania/src/GameState.cpp | 4 ++++ stepmania/src/Song.cpp | 32 ++++++++++++++++++++++++++++++++ stepmania/src/Steps.cpp | 25 +++++++++++++++++++++++++ stepmania/src/Steps.h | 4 ++++ stepmania/src/song.h | 4 ++++ 5 files changed, 69 insertions(+) diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index ed8652f05a..83e2310e27 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -1873,6 +1873,8 @@ public: p->ApplyGameCommand(SArg(1),pn); return 0; } + static int GetCurrentSong( T* p, lua_State *L ) { if(p->m_pCurSong) p->m_pCurSong->PushSelf(L); else lua_pushnil(L); return 1; } + static int SetCurrentSong( T* p, lua_State *L ) { Song *pS = Luna::check(L,1); p->m_pCurSong = pS; return 0; } static int GetCurrentCourse( T* p, lua_State *L ) { if(p->m_pCurCourse) p->m_pCurCourse->PushSelf(L); else lua_pushnil(L); return 1; } static int SetCurrentCourse( T* p, lua_State *L ) { Course *pC = Luna::check(L,1); p->m_pCurCourse = pC; return 0; } static int SetTemporaryEventMode( T* p, lua_State *L ) { p->m_bTemporaryEventMode = BArg(1); return 0; } @@ -1884,6 +1886,8 @@ public: ADD_METHOD( GetPlayerDisplayName ) ADD_METHOD( GetMasterPlayerNumber ) ADD_METHOD( ApplyGameCommand ) + ADD_METHOD( GetCurrentSong ) + ADD_METHOD( SetCurrentSong ) ADD_METHOD( GetCurrentCourse ) ADD_METHOD( SetCurrentCourse ) ADD_METHOD( SetTemporaryEventMode ) diff --git a/stepmania/src/Song.cpp b/stepmania/src/Song.cpp index 0636e63fb2..a2e4f003ae 100644 --- a/stepmania/src/Song.cpp +++ b/stepmania/src/Song.cpp @@ -1404,6 +1404,38 @@ bool Song::HasSignificantBpmChangesOrStops() const return m_Timing.HasBpmChangesOrStops(); } + +// lua start +#include "LuaBinding.h" + +template +class LunaSong : public Luna +{ +public: + LunaSong() { LUA->Register( Register ); } + + static int GetFullDisplayTitle( T* p, lua_State *L ) { lua_pushstring(L, p->GetFullDisplayTitle() ); return 1; } + static int GetFullTranslitTitle( T* p, lua_State *L ) { lua_pushstring(L, p->GetFullTranslitTitle() ); return 1; } + static int GetAllSteps( T* p, lua_State *L ) + { + const vector &v = p->GetAllSteps(); + CreateTableFromArray( v, L ); + return 1; + } + + static void Register(lua_State *L) + { + ADD_METHOD( GetFullDisplayTitle ) + ADD_METHOD( GetFullTranslitTitle ) + ADD_METHOD( GetAllSteps ) + Luna::Register( L ); + } +}; + +LUA_REGISTER_CLASS( Song ) +// lua end + + /* * (c) 2001-2004 Chris Danford, Glenn Maynard * All rights reserved. diff --git a/stepmania/src/Steps.cpp b/stepmania/src/Steps.cpp index 9504835901..69dce7975a 100644 --- a/stepmania/src/Steps.cpp +++ b/stepmania/src/Steps.cpp @@ -326,6 +326,31 @@ void Steps::SetRadarValues( const RadarValues& v ) m_RadarValues = v; } + +// lua start +#include "LuaBinding.h" + +template +class LunaSteps : public Luna +{ +public: + LunaSteps() { LUA->Register( Register ); } + + static int GetStepsType( T* p, lua_State *L ) { lua_pushnumber(L, p->m_StepsType ); return 1; } + static int GetDescription( T* p, lua_State *L ) { lua_pushstring(L, p->GetDescription() ); return 1; } + + static void Register(lua_State *L) + { + ADD_METHOD( GetStepsType ) + ADD_METHOD( GetDescription ) + Luna::Register( L ); + } +}; + +LUA_REGISTER_CLASS( Steps ) +// lua end + + /* * (c) 2001-2004 Chris Danford, Glenn Maynard, David Wilson * All rights reserved. diff --git a/stepmania/src/Steps.h b/stepmania/src/Steps.h index de0fc210cb..0e5454d1f6 100644 --- a/stepmania/src/Steps.h +++ b/stepmania/src/Steps.h @@ -10,6 +10,7 @@ #include "Difficulty.h" class NoteData; class Profile; +struct lua_State; class Steps { @@ -55,6 +56,9 @@ public: void TidyUpData(); + // Lua + void PushSelf( lua_State *L ); + protected: /* If this Steps is autogenerated, this will point to the autogen * source. If this is true, notes_comp will always be NULL. */ diff --git a/stepmania/src/song.h b/stepmania/src/song.h index 63b1f1fde3..134a7670a8 100644 --- a/stepmania/src/song.h +++ b/stepmania/src/song.h @@ -15,6 +15,7 @@ class NotesLoader; class LyricsLoader; class Profile; class StepsID; +struct lua_State; #define MAX_EDITS_PER_SONG_PER_PROFILE 5 #define MAX_EDITS_PER_SONG 5*NUM_PROFILE_SLOTS @@ -224,6 +225,9 @@ public: // means "this note doens't have a keysound". vector m_vsKeysoundFile; + // Lua + void PushSelf( lua_State *L ); + private: void AdjustDuplicateSteps(); // part of TidyUpData void DeleteDuplicateSteps( vector &vSteps );