awful.util: add table.keys_filtered

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:29 +02:00 committed by Julien Danjou
parent f337b88a73
commit b5fadb97cf
1 changed files with 18 additions and 0 deletions

View File

@ -298,4 +298,22 @@ function table.keys(t)
return keys return keys
end end
--- Filter a tables keys for certain content types
-- @param t The table to retrieve the keys for
-- @param ... the types to look for
-- @return A filtered table with keys
function table.keys_filter(t, ...)
local keys = table.keys(t)
local keys_filtered = { }
for _, k in pairs(keys) do
for _, et in pairs(arg) do
if type(t[k]) == et then
rtable.insert(keys_filtered, k)
break
end
end
end
return keys_filtered
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