add LuaTable

This commit is contained in:
Glenn Maynard
2005-03-18 22:40:09 +00:00
parent 501e609dfc
commit 627e5eb16a
2 changed files with 49 additions and 0 deletions
+32
View File
@@ -201,6 +201,38 @@ void LuaData::Register()
m_sSerializedData.erase( m_sSerializedData.begin(), m_sSerializedData.end() );
}
LuaTable::LuaTable()
{
lua_newtable( LUA->L );
this->SetFromStack();
}
void LuaTable::Set( const CString &sKey )
{
int iTop = lua_gettop( LUA->L );
this->PushSelf( LUA->L );
lua_pushstring( LUA->L, sKey ); // push the key
lua_pushvalue( LUA->L, iTop ); // push the value
lua_settable( LUA->L, iTop+1 );
lua_settop( LUA->L, iTop-1 ); // remove all of the above
}
void LuaTable::Unset( const CString &sKey )
{
lua_pushnil( LUA->L );
Set( sKey );
}
void LuaTable::SetKeyAndValue()
{
int iTop = lua_gettop( LUA->L );
this->PushSelf( LUA->L );
lua_pushvalue( LUA->L, iTop-1 ); // push the value after the table
lua_pushvalue( LUA->L, iTop ); // push the key after the value
lua_settable( LUA->L, iTop+1 );
lua_settop( LUA->L, iTop-1 ); // remove all of the above
}
/*
* (c) 2005 Glenn Maynard, Chris Danford
* All rights reserved.
+17
View File
@@ -80,6 +80,23 @@ protected:
bool m_bWasSet;
};
class LuaTable: public LuaData
{
public:
LuaTable();
/* Set a key by the given name to a value on the stack, and pop the value
* off the stack. */
void Set( const CString &sKey );
/* Unset the given key (set it to nil). */
void Unset( const CString &sKey );
/* Set a key on the stack to a value on the stack; push the key first. Pop
* both the key and the value off the stack. */
void SetKeyAndValue();
};
#endif
/*