From d7bcadccc78e0a0db3bdeaa56f761008a2b851b6 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Mon, 21 Feb 2005 17:26:43 +0000 Subject: [PATCH] add Lua bindings --- stepmania/src/SongManager.cpp | 45 +++++++++++++++++++++++++++++++++++ stepmania/src/SongManager.h | 4 ++++ 2 files changed, 49 insertions(+) diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp index e5d20860bf..d32de08950 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -1228,6 +1228,51 @@ void SongManager::FreeAllLoadedFromProfiles() StepsID::ClearCache(); } + + +// lua start +#include "LuaBinding.h" + +template +class LunaSongManager : public Luna +{ +public: + LunaSongManager() { LUA->Register( Register ); } + + static int GetAllCourses( T* p, lua_State *L ) + { + vector vCourses; + p->GetAllCourses( vCourses, BArg(1) ); + CreateTableFromArray( vCourses, L ); + return 1; + } + static int FindCourse( T* p, lua_State *L ) { Course *pC = p->FindCourse(SArg(1)); if(pC) pC->PushSelf(L); else lua_pushnil(L); return 1; } + + static void Register(lua_State *L) + { + ADD_METHOD( GetAllCourses ) + ADD_METHOD( FindCourse ) + Luna::Register( L ); + + // Add global singleton if constructed already. If it's not constructed yet, + // then we'll register it later when we reinit Lua just before + // initializing the display. + if( SONGMAN ) + { + lua_pushstring(L, "SONGMAN"); + SONGMAN->PushSelf( LUA->L ); + lua_settable(L, LUA_GLOBALSINDEX); + } + } +}; + +LUA_REGISTER_CLASS( SongManager ) +// lua end + + + + + static bool CheckPointer( const Song *p ) { const vector &songs = SONGMAN->GetAllSongs(); diff --git a/stepmania/src/SongManager.h b/stepmania/src/SongManager.h index 774efd8147..cb855b160e 100644 --- a/stepmania/src/SongManager.h +++ b/stepmania/src/SongManager.h @@ -9,6 +9,7 @@ class Style; class Course; class Steps; struct PlayerOptions; +struct lua_State; #include "RageTypes.h" #include "GameConstantsAndTypes.h" @@ -95,6 +96,9 @@ public: void UpdateRankingCourses(); // courses shown on the ranking screen + // Lua + void PushSelf( lua_State *L ); + protected: void LoadStepManiaSongDir( CString sDir, LoadingWindow *ld ); void LoadDWISongDir( CString sDir );