From b5fadb97cfcf69b2ccbf8401a2fbeea37d3d4538 Mon Sep 17 00:00:00 2001 From: Gregor Best Date: Thu, 2 Jul 2009 02:05:29 +0200 Subject: [PATCH] awful.util: add table.keys_filtered 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 43dc09520..ad43f6ef1 100644 --- a/lib/awful/util.lua.in +++ b/lib/awful/util.lua.in @@ -298,4 +298,22 @@ function table.keys(t) return keys 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