From b50d783928a0d6390210481ee10e4b83d6f48004 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89tienne=20Reuh=20Fildadut?= Date: Fri, 9 Sep 2022 12:19:50 +0900 Subject: [PATCH] Also copy keys when copying variables --- common.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common.lua b/common.lua index cfb3a25..c43a2d6 100644 --- a/common.lua +++ b/common.lua @@ -15,8 +15,8 @@ local function replace_in_table(t, to_replace, already_replaced) end common = { - --- recursively copy a table, handle cyclic references, no metatable, don't copy keys - -- cache is table with copied tables [original table] = copied value, will use temporary table is omitted + --- recursively copy a table (key & values), handle cyclic references, no metatable + -- cache is table with copied tables [original table] = copied value, will create temporary table if argument is omitted copy = function(t, cache) if type(t) == "table" then cache = cache or {} @@ -26,7 +26,7 @@ common = { local c = {} cache[t] = c for k, v in pairs(t) do - c[k] = common.copy(v, cache) + c[common.copy(k, cache)] = common.copy(v, cache) end return c end