awful.util: add table.hasitem()

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-04-27 18:33:15 +02:00
parent efad1b9843
commit cd84fd5ebd
1 changed files with 12 additions and 0 deletions

View File

@ -237,4 +237,16 @@ function table.join(...)
return ret
end
--- Check if a table has an item and return its key.
-- @param t The table.
-- @param item The item to look for in values of the table.
-- @return The key were the item is found, or nil if not found.
function table.hasitem(t, item)
for k, v in pairs(t) do
if v == item then
return k
end
end
end
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80