awful.util: add table.reverse

Signed-off-by: Gregor Best <farhaven@googlemail.com>
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Gregor Best 2009-07-02 02:05:42 +02:00 committed by Julien Danjou
parent b5fadb97cf
commit 7a7314e068
1 changed files with 18 additions and 0 deletions

View File

@ -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