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 <git@thequod.de>
This commit is contained in:
Daniel Hahler 2014-03-14 17:10:24 +01:00 committed by Uli Schlachter
parent b1c14d5660
commit 11f7b5aa3d
1 changed files with 4 additions and 2 deletions

View File

@ -436,11 +436,13 @@ end
--- Clone a table --- Clone a table
-- @param t the table to clone -- @param t the table to clone
-- @param deep Create a deep clone? (default: true)
-- @return a clone of t -- @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 = { } local c = { }
for k, v in pairs(t) do 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) c[k] = util.table.clone(v)
else else
c[k] = v c[k] = v