From 926dd348e437ca1a174d53c215dc1f1aa2af19ca Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Fri, 14 Mar 2014 17:10:24 +0100 Subject: [PATCH] Add a "deep" option to awful.util.table.clone This allows for having clones of a table, where its entries are still references to the original values. This is useful for copying a "default props" table, where you want to keep the reference to entries like `awful.layout.suit.tile`. Signed-off-by: Daniel Hahler --- lib/awful/util.lua.in | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/awful/util.lua.in b/lib/awful/util.lua.in index 0a90b76a7..4c6424d8e 100644 --- a/lib/awful/util.lua.in +++ b/lib/awful/util.lua.in @@ -436,11 +436,13 @@ end --- Clone a table -- @param t the table to clone +-- @param deep Create a deep clone? (default: true) -- @return a clone of t -function util.table.clone(t) +function util.table.clone(t, deep) + local deep = deep == nil and true or deep local c = { } for k, v in pairs(t) do - if type(v) == "table" then + if deep and type(v) == "table" then c[k] = util.table.clone(v) else c[k] = v