diff --git a/stepmania/src/GameCommand.cpp b/stepmania/src/GameCommand.cpp index 9490e76e1b..a87310d052 100644 --- a/stepmania/src/GameCommand.cpp +++ b/stepmania/src/GameCommand.cpp @@ -694,7 +694,14 @@ void GameCommand::ApplySelf( const vector &vpns ) const FOREACH_CONST( PlayerNumber, vpns, pn ) GAMESTATE->m_pCurCharacters[*pn] = m_pCharacter; for( map::const_iterator i = m_SetEnv.begin(); i != m_SetEnv.end(); i++ ) - GAMESTATE->m_mapEnv[ i->first ] = i->second; + { + Lua *L = LUA->Get(); + GAMESTATE->m_Environment->PushSelf(L); + lua_pushstring( L, i->first ); + lua_pushstring( L, i->second ); + lua_settable( L, -3 ); + LUA->Release(L); + } if( !m_sSongGroup.empty() ) GAMESTATE->m_sPreferredSongGroup.Set( m_sSongGroup ); if( m_SortOrder != SORT_INVALID ) diff --git a/stepmania/src/GameState.cpp b/stepmania/src/GameState.cpp index dafa761431..be0c03830a 100644 --- a/stepmania/src/GameState.cpp +++ b/stepmania/src/GameState.cpp @@ -178,7 +178,7 @@ void GameState::Reset() // m_iCoins = 0; // don't reset coin count! m_MasterPlayerNumber = PLAYER_INVALID; m_bMultiplayer = false; - m_mapEnv.clear(); + *m_Environment = LuaTable(); m_sPreferredSongGroup.Set( GROUP_ALL ); m_sPreferredCourseGroup.Set( GROUP_ALL ); m_bChangedFailTypeOnScreenSongOptions = false; @@ -726,6 +726,7 @@ Stage GameState::GetCurrentStage() const else return (Stage)(STAGE_1+m_iCurrentStageIndex); } +// Return true if it's possible for GetCurrentStage() to return the given stage. bool GameState::IsStagePossible( Stage s ) const { /* HACK: Find out what the stage would be without long or marathon. @@ -1883,14 +1884,21 @@ public: } static int SetTemporaryEventMode( T* p, lua_State *L ) { p->m_bTemporaryEventMode = BArg(1); return 0; } static int Env( T* p, lua_State *L ) { p->m_Environment->PushSelf(L); return 1; } - static int SetEnv( T* p, lua_State *L ) { p->m_mapEnv[SArg(1)] = SArg(2); return 0; } + static int SetEnv( T* p, lua_State *L ) + { + int iTop = lua_gettop(L); + p->m_Environment->PushSelf(L); + lua_pushvalue( L, iTop-1 ); + lua_pushvalue( L, iTop ); + lua_settable( L, -3 ); + return 0; + } static int GetEnv( T* p, lua_State *L ) { - map::const_iterator iter = p->m_mapEnv.find(SArg(1)); - if( iter != p->m_mapEnv.end() ) - lua_pushstring(L,iter->second); - else - lua_pushnil(L); + int iTop = lua_gettop(L); + p->m_Environment->PushSelf(L); + lua_pushvalue( L, iTop ); + lua_gettable( L, -2 ); return 1; } static int GetEditSourceSteps( T* p, lua_State *L ) diff --git a/stepmania/src/GameState.h b/stepmania/src/GameState.h index 57fe2168a7..ade46b5331 100644 --- a/stepmania/src/GameState.h +++ b/stepmania/src/GameState.h @@ -69,7 +69,6 @@ public: bool IsCourseDifficultyShown( CourseDifficulty cd ); Difficulty GetEasiestStepsDifficulty() const; RageTimer m_timeGameStarted; // from the moment the first player pressed Start - map m_mapEnv; LuaTable *m_Environment; /* This is set to a random number per-game/round; it can be used for a random seed. */