diff --git a/stepmania/src/ActorUtil.cpp b/stepmania/src/ActorUtil.cpp index 6c9b2a793c..e0fbc466fd 100644 --- a/stepmania/src/ActorUtil.cpp +++ b/stepmania/src/ActorUtil.cpp @@ -528,6 +528,35 @@ FileType ActorUtil::GetFileType( const CString &sPath ) else return FT_Invalid; } +/* Helper: set actor parameters, and return them to their original value when released. */ +ActorUtil::ActorParam::ActorParam( CString sName, CString sValue ) +{ + m_pOld = new LuaReference; + m_sName = sName; + Lua *L = LUA->Get(); + LuaHelpers::Push( sValue, L ); + ActorUtil::SetParamFromStack( L, m_sName, m_pOld ); + LUA->Release( L ); +} + +ActorUtil::ActorParam::~ActorParam() +{ + delete m_pOld; + Release(); +} + +void ActorUtil::ActorParam::Release() +{ + if( m_pOld->IsSet() ) + return; + /* Restore the old value. */ + Lua *L = LUA->Get(); + m_pOld->PushSelf( L ); + ActorUtil::SetParamFromStack( L, m_sName ); + m_pOld->Unset(); + LUA->Release( L ); +} + /* * (c) 2003-2004 Chris Danford * All rights reserved. diff --git a/stepmania/src/ActorUtil.h b/stepmania/src/ActorUtil.h index f6b7fcefad..57fc289f36 100644 --- a/stepmania/src/ActorUtil.h +++ b/stepmania/src/ActorUtil.h @@ -77,6 +77,17 @@ namespace ActorUtil void SetParamFromStack( Lua *L, CString sName, LuaReference *pOld=NULL ); void GetParam( Lua *L, const CString &sName ); + + struct ActorParam + { + ActorParam( CString sName, CString sValue ); + ~ActorParam(); + void Release(); + + private: + CString m_sName; + LuaReference *m_pOld; + }; }; #define SET_XY( actor ) ActorUtil::SetXY( actor, m_sName ) diff --git a/stepmania/src/Screen.cpp b/stepmania/src/Screen.cpp index 94d05ce39f..7bcbd0541d 100644 --- a/stepmania/src/Screen.cpp +++ b/stepmania/src/Screen.cpp @@ -20,23 +20,9 @@ void Screen::InitScreen( Screen *pScreen ) { /* Set the name of the loading screen. */ - LuaReference Old; - { - Lua *L = LUA->Get(); - LuaHelpers::Push( pScreen->GetName(), L ); - ActorUtil::SetParamFromStack( L, "LoadingScreen", &Old ); - LUA->Release( L ); - } + ActorUtil::ActorParam LoadingScreen( "LoadingScreen", pScreen->GetName() ); pScreen->Init(); - - /* Restore the old value. */ - { - Lua *L = LUA->Get(); - Old.PushSelf( L ); - ActorUtil::SetParamFromStack( L, "LoadingScreen" ); - LUA->Release( L ); - } } Screen::Screen( CString sName )