awful.util: add table.hasitem()
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
efad1b9843
commit
cd84fd5ebd
|
@ -237,4 +237,16 @@ function table.join(...)
|
||||||
return ret
|
return ret
|
||||||
end
|
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
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|
||||||
|
|
Loading…
Reference in New Issue