diff --git a/stepmania/src/LuaReference.cpp b/stepmania/src/LuaReference.cpp index 65a7093c68..85b23bd06c 100644 --- a/stepmania/src/LuaReference.cpp +++ b/stepmania/src/LuaReference.cpp @@ -193,6 +193,13 @@ void LuaTable::Set( Lua *L, const RString &sKey ) lua_settop( L, iTop-1 ); // remove all of the above } +void LuaTable::Get( Lua *L, const RString &sKey ) +{ + this->PushSelf( L ); + lua_getfield( L, -1, sKey ); + lua_remove( L, -2 ); // remove self +} + namespace LuaHelpers { template<> void Push( lua_State *L, const LuaReference &Object ) diff --git a/stepmania/src/LuaReference.h b/stepmania/src/LuaReference.h index 1d8eda4b03..d470a8791b 100644 --- a/stepmania/src/LuaReference.h +++ b/stepmania/src/LuaReference.h @@ -81,6 +81,9 @@ class LuaTable: public LuaReference public: LuaTable(); + /* Get the key with the given name, and push it on the stack. */ + void Get( Lua *L, const RString &sKey ); + /* Set a key by the given name to a value on the stack, and pop the value * off the stack. */ void Set( Lua *L, const RString &sKey ); diff --git a/stepmania/src/MessageManager.cpp b/stepmania/src/MessageManager.cpp index ac6fe1c75e..b30cbfd117 100644 --- a/stepmania/src/MessageManager.cpp +++ b/stepmania/src/MessageManager.cpp @@ -174,6 +174,11 @@ const LuaReference &Message::GetParamTable() const return *m_pParams; } +void Message::GetParamFromStack( lua_State *L, const RString &sName ) const +{ + m_pParams->Get( L, sName ); +} + void Message::SetParamFromStack( lua_State *L, const RString &sName ) { m_pParams->Set( L, sName ); diff --git a/stepmania/src/MessageManager.h b/stepmania/src/MessageManager.h index 2002d5a42e..795c6d396c 100644 --- a/stepmania/src/MessageManager.h +++ b/stepmania/src/MessageManager.h @@ -156,8 +156,19 @@ struct Message void PushParamTable( lua_State *L ); const LuaReference &GetParamTable() const; + void GetParamFromStack( lua_State *L, const RString &sName ) const; void SetParamFromStack( lua_State *L, const RString &sName ); + template + bool GetParam( const RString &sName, T &val ) const + { + Lua *L = LUA->Get(); + GetParamFromStack( L, sName ); + bool bRet = LuaHelpers::Pop( L, val ); + LUA->Release( L ); + return bRet; + } + template void SetParam( const RString &sName, const T &val ) {