diff --git a/stepmania/src/LuaReference.cpp b/stepmania/src/LuaReference.cpp index f3a6c13aed..c98ba715be 100644 --- a/stepmania/src/LuaReference.cpp +++ b/stepmania/src/LuaReference.cpp @@ -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 ); diff --git a/stepmania/src/LuaReference.h b/stepmania/src/LuaReference.h index cc011a77a2..c13b5b0074 100644 --- a/stepmania/src/LuaReference.h +++ b/stepmania/src/LuaReference.h @@ -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;