add LuaReference::DeepCopy

This commit is contained in:
Glenn Maynard
2005-08-29 06:30:44 +00:00
parent f292ab69ef
commit ba0eb8dba2
2 changed files with 23 additions and 0 deletions
+20
View File
@@ -76,6 +76,26 @@ void LuaReference::SetFromNil()
m_iReference = LUA_REFNIL;
}
void LuaReference::DeepCopy()
{
/* Call DeepCopy(t), where t is our referenced object. */
Lua *L = LUA->Get();
lua_pushstring( L, "DeepCopy" );
lua_gettable( L, LUA_GLOBALSINDEX );
ASSERT_M( !lua_isnil(L, -1), "DeepCopy() missing" );
ASSERT_M( lua_isfunction(L, -1), "DeepCopy() not a function" );
/* Arg 1 (t): */
this->PushSelf( L );
lua_call( L, 1, 1 );
this->SetFromStack( L );
LUA->Release( L );
}
void LuaReference::PushSelf( lua_State *L ) const
{
lua_rawgeti( L, LUA_REGISTRYINDEX, m_iReference );
+3
View File
@@ -21,6 +21,9 @@ public:
void SetFromStack( Lua *L );
void SetFromNil();
/* Deep-copy tables, detaching this reference from any others. */
void DeepCopy();
/* Push the referenced object onto the stack. If not set (or set to nil), push nil. */
virtual void PushSelf( Lua *L ) const;