From 9cd29814f03f715d5adba8645a60c25b6aaba4ca Mon Sep 17 00:00:00 2001 From: Gregor Best Date: Thu, 25 Jun 2009 01:15:07 +0200 Subject: [PATCH] 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 Signed-off-by: Julien Danjou --- lib/awful/util.lua.in | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/lib/awful/util.lua.in b/lib/awful/util.lua.in index 9f0cdc406..861a0e896 100644 --- a/lib/awful/util.lua.in +++ b/lib/awful/util.lua.in @@ -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