getters
This commit is contained in:
@@ -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<LuaReference>( lua_State *L, const LuaReference &Object )
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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<typename T>
|
||||
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<typename T>
|
||||
void SetParam( const RString &sName, const T &val )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user