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:
Gregor Best 2009-06-25 01:15:07 +02:00 committed by Julien Danjou
parent 7a7314e068
commit 9cd29814f0
1 changed files with 11 additions and 0 deletions

View File

@ -334,4 +334,15 @@ function table.reverse(t)
return tr
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