From 7a7314e0683361496d6c1d331d280d70d271aa20 Mon Sep 17 00:00:00 2001 From: Gregor Best Date: Thu, 2 Jul 2009 02:05:42 +0200 Subject: [PATCH] awful.util: add table.reverse Signed-off-by: Gregor Best Signed-off-by: Julien Danjou --- lib/awful/util.lua.in | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/lib/awful/util.lua.in b/lib/awful/util.lua.in index ad43f6ef..9f0cdc40 100644 --- a/lib/awful/util.lua.in +++ b/lib/awful/util.lua.in @@ -316,4 +316,22 @@ function table.keys_filter(t, ...) return keys_filtered end +--- Reverse a table +-- @param t the table to reverse +-- @return the reversed table +function table.reverse(t) + local tr = { } + -- reverse all elements with integer keys + for _, v in ipairs(t) do + rtable.insert(tr, 1, v) + end + -- add the remaining elements + for k, v in pairs(t) do + if type(v) ~= "number" then + tr[k] = v + end + end + return tr +end + -- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80