X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/c0c6ff6136ed5d29f3b688b0772278ccfea8ac69..bc6e45effd2e9460dd74972af247ba21182fd777:/src/bindings/lua/lua_state_cloner.c diff --git a/src/bindings/lua/lua_state_cloner.c b/src/bindings/lua/lua_state_cloner.c index c5abebbc97..27a79d64c8 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); } @@ -414,7 +426,7 @@ static void sglua_copy_function(lua_State* src, lua_State* dst) { buffer.data = xbt_new(char, buffer.capacity); /* copy the binary chunk from src into a buffer */ - int error = lua_dump(src, sglua_memory_writer, &buffer); + _XBT_GNUC_UNUSED int error = lua_dump(src, sglua_memory_writer, &buffer); xbt_assert(!error, "Failed to dump the function from the source state: error %d", error); XBT_DEBUG("Fonction dumped: %zu bytes", buffer.size); @@ -610,7 +622,7 @@ lua_State* sglua_clone_maestro(void) { /* create the table of known tables from maestro */ lua_pushstring(L, "simgrid.maestro_tables"); /* "simgrid.maestro_tables" */ - lua_newtable(L); /* "simgrid.maestro_tables" maestrotbs*/ + lua_newtable(L); /* "simgrid.maestro_tables" maestrotbs */ lua_rawset(L, LUA_REGISTRYINDEX); /* -- */