From ac10e10c4e1f3ff2c05a5d5b5400026f66746615 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Christophe=20Thi=C3=A9ry?= Date: Mon, 7 Nov 2011 19:20:49 +0100 Subject: [PATCH] Lua: add a function sglua_copy_value --- src/bindings/lua/lua_state_cloner.c | 22 +++++++++++++++++----- src/bindings/lua/lua_state_cloner.h | 1 + 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/bindings/lua/lua_state_cloner.c b/src/bindings/lua/lua_state_cloner.c index 1ce36209dc..13c6ff57e4 100644 --- a/src/bindings/lua/lua_state_cloner.c +++ b/src/bindings/lua/lua_state_cloner.c @@ -134,7 +134,22 @@ static void sglua_get_table_by_ptr(lua_State* L, void* maestro_table_ptr) { * @param src the source state (not necessarily maestro) * @param dst the destination state */ -void sglua_move_value(lua_State* src, lua_State *dst) { +void sglua_move_value(lua_State* src, lua_State* dst) { + + sglua_copy_value(src, dst); + lua_pop(src, 1); +} + +/** + * @brief Pushes onto the stack a copy of the value on top another stack. + * If the value is a table, its content is copied recursively. + * + * This function allows to move a value between two different global states. + * + * @param src the source state (not necessarily maestro) + * @param dst the destination state + */ +void sglua_copy_value(lua_State* src, lua_State* dst) { luaL_checkany(src, -1); /* check the value to copy */ @@ -183,13 +198,10 @@ void sglua_move_value(lua_State* src, lua_State *dst) { break; } - /* the value has been copied to dst: remove it from src */ - lua_pop(src, 1); - indent -= 2; XBT_DEBUG("%sData copied", sglua_get_spaces(indent)); - sglua_stack_dump("src after copying a value (should be ...): ", src); + sglua_stack_dump("src after copying a value (should be ... value): ", src); sglua_stack_dump("dst after copying a value (should be ... value): ", dst); } diff --git a/src/bindings/lua/lua_state_cloner.h b/src/bindings/lua/lua_state_cloner.h index 57b859985f..875fb3185b 100644 --- a/src/bindings/lua/lua_state_cloner.h +++ b/src/bindings/lua/lua_state_cloner.h @@ -14,5 +14,6 @@ int sglua_is_maestro(lua_State* L); lua_State* sglua_get_maestro(void); lua_State* sglua_clone_maestro(void); void sglua_move_value(lua_State* src, lua_State* dst); +void sglua_copy_value(lua_State* src, lua_State* dst); #endif /* LUA_STATE_CLONER_H */ -- 2.20.1