From 10b96b08b8dee4fb9d107fb8f367796121a35f31 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Sun, 15 Oct 2006 01:40:11 +0000 Subject: [PATCH] LuaHelpers::DeepCopy --- stepmania/src/LuaManager.cpp | 15 +++++++++++++++ stepmania/src/LuaManager.h | 4 ++++ 2 files changed, 19 insertions(+) diff --git a/stepmania/src/LuaManager.cpp b/stepmania/src/LuaManager.cpp index 8824c7e94d..99af8fe295 100644 --- a/stepmania/src/LuaManager.cpp +++ b/stepmania/src/LuaManager.cpp @@ -659,6 +659,21 @@ int LuaHelpers::TypeError( Lua *L, int iArgNo, const char *szName ) } } +void LuaHelpers::DeepCopy( lua_State *L ) +{ + luaL_checktype( L, -2, LUA_TTABLE ); + luaL_checktype( L, -1, LUA_TTABLE ); + + /* Call DeepCopy(t, u), where t is our referenced object and u is the new table. */ + lua_getglobal( L, "DeepCopy" ); + + ASSERT_M( !lua_isnil(L, -1), "DeepCopy() missing" ); + ASSERT_M( lua_isfunction(L, -1), "DeepCopy() not a function" ); + lua_insert( L, lua_gettop(L)-2 ); + + lua_call( L, 2, 0 ); +} + namespace { int lua_pushvalues( lua_State *L ) diff --git a/stepmania/src/LuaManager.h b/stepmania/src/LuaManager.h index e6b709db17..c643be3412 100644 --- a/stepmania/src/LuaManager.h +++ b/stepmania/src/LuaManager.h @@ -62,6 +62,10 @@ namespace LuaHelpers /* Create a Lua array (a table with indices starting at 1) of the given vector, * and push it on the stack. */ void CreateTableFromArrayB( Lua *L, const vector &aIn ); + + /* Recursively copy elements from the table at stack element -2 into the table + * at stack -1. Pop both elements from the stack. */ + void DeepCopy( lua_State *L ); /* Read the table at the top of the stack back into a vector. */ void ReadArrayFromTableB( Lua *L, vector &aOut );