From 6f6ef25d1d7474f9338b7ad357fee17f3eeea14d Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Wed, 23 Feb 2005 05:02:28 +0000 Subject: [PATCH] add Lua bindings --- stepmania/src/GameConstantsAndTypes.cpp | 8 ++++---- stepmania/src/GameState.cpp | 16 ++++++++++++---- stepmania/src/SongManager.cpp | 2 ++ stepmania/src/Steps.cpp | 2 ++ 4 files changed, 20 insertions(+), 8 deletions(-) diff --git a/stepmania/src/GameConstantsAndTypes.cpp b/stepmania/src/GameConstantsAndTypes.cpp index a3c8945630..23e674bd4e 100644 --- a/stepmania/src/GameConstantsAndTypes.cpp +++ b/stepmania/src/GameConstantsAndTypes.cpp @@ -26,7 +26,7 @@ XToString( RadarCategory ); XToThemedString( RadarCategory, NUM_RADAR_CATEGORIES ); -void LuaStepsType(lua_State* L) +static void LuaStepsType(lua_State* L) { FOREACH_StepsType( st ) { @@ -50,7 +50,7 @@ static const CString PlayModeNames[NUM_PLAY_MODES] = { XToString( PlayMode ); XToThemedString( PlayMode, NUM_PLAY_MODES ); StringToX( PlayMode ); -void LuaPlayMode(lua_State* L) +static void LuaPlayMode(lua_State* L) { FOREACH_PlayMode( pm ) { @@ -281,7 +281,7 @@ static const CString GoalTypeNames[NUM_GOAL_TYPES] = { }; XToString( GoalType ); StringToX( GoalType ); -void LuaGoalType(lua_State* L) +static void LuaGoalType(lua_State* L) { FOREACH_GoalType( gt ) { @@ -302,7 +302,7 @@ static const CString EditMenuActionNames[NUM_EDIT_MENU_ACTIONS] = { }; XToString( EditMenuAction ); StringToX( EditMenuAction ); -void LuaEditMenuAction(lua_State* L) +static void LuaEditMenuAction(lua_State* L) { FOREACH_EditMenuAction( ema ) { diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index 197ae73914..5a00d68713 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -1804,8 +1804,15 @@ public: 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 ) { - if( lua_isnil(L,1) ) { p->m_pCurSong = NULL; } - else { Song *pS = Luna::check(L,1); p->m_pCurSong = pS; } + if( lua_isnil(L,1) ) + { + p->m_pCurSong = NULL; + } + else + { + Song *pS = Luna::check(L,1); + p->m_pCurSong = pS; + } return 0; } static int GetCurrentSteps( T* p, lua_State *L ) @@ -1819,9 +1826,8 @@ public: static int SetCurrentSteps( T* p, lua_State *L ) { PlayerNumber pn = (PlayerNumber)IArg(1); - Steps *pSteps = p->m_pCurSteps[pn]; if( lua_isnil(L,2) ) { p->m_pCurSteps[pn] = NULL; } - else { Song *pS = Luna::check(L,2); p->m_pCurSteps[pn] = pS; } + else { Steps *pS = Luna::check(L,2); p->m_pCurSteps[pn] = 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; } @@ -1842,6 +1848,8 @@ public: ADD_METHOD( ApplyGameCommand ) ADD_METHOD( GetCurrentSong ) ADD_METHOD( SetCurrentSong ) + ADD_METHOD( GetCurrentSteps ) + ADD_METHOD( SetCurrentSteps ) ADD_METHOD( GetCurrentCourse ) ADD_METHOD( SetCurrentCourse ) ADD_METHOD( SetTemporaryEventMode ) diff --git a/stepmania/src/SongManager.cpp b/stepmania/src/SongManager.cpp index add33fcc50..908b6d2907 100644 --- a/stepmania/src/SongManager.cpp +++ b/stepmania/src/SongManager.cpp @@ -1252,12 +1252,14 @@ public: CreateTableFromArray( v, L ); return 1; } + static int FindSong( T* p, lua_State *L ) { Song *pS = p->FindSong(SArg(1)); if(pS) pS->PushSelf(L); else lua_pushnil(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( GetAllSongs ) ADD_METHOD( GetAllCourses ) + ADD_METHOD( FindSong ) ADD_METHOD( FindCourse ) Luna::Register( L ); diff --git a/stepmania/src/Steps.cpp b/stepmania/src/Steps.cpp index 69dce7975a..3ab7f6037f 100644 --- a/stepmania/src/Steps.cpp +++ b/stepmania/src/Steps.cpp @@ -337,11 +337,13 @@ public: LunaSteps() { LUA->Register( Register ); } static int GetStepsType( T* p, lua_State *L ) { lua_pushnumber(L, p->m_StepsType ); return 1; } + static int GetDifficulty( T* p, lua_State *L ) { lua_pushnumber(L, p->GetDifficulty() ); 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( GetDifficulty ) ADD_METHOD( GetDescription ) Luna::Register( L ); }