awful.util: add table.clone
This is useful because tables get passed by reference instead of by value, so we might end up modifying tables where we don't want it. Signed-off-by: Gregor Best <farhaven@googlemail.com> Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
7a7314e068
commit
9cd29814f0
|
@ -334,4 +334,15 @@ function table.reverse(t)
|
||||||
return tr
|
return tr
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- Clone a table
|
||||||
|
-- @param t the table to clone
|
||||||
|
-- @return a clone of t
|
||||||
|
function table.clone(t)
|
||||||
|
local c = { }
|
||||||
|
for k, v in pairs(t) do
|
||||||
|
c[k] = v
|
||||||
|
end
|
||||||
|
return c
|
||||||
|
end
|
||||||
|
|
||||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||||
|
|
Loading…
Reference in New Issue