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:
parent
c855b1babb
commit
926dd348e4
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue