awful.util: table.join support for non-integer keys

Signed-off-by: koniu <gkusnierz@gmail.com>
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
koniu 2009-04-18 21:44:36 +01:00 committed by Julien Danjou
parent 715f95555a
commit b9ca6b4961
1 changed files with 10 additions and 5 deletions

View File

@ -14,7 +14,7 @@ local debug = debug
local print = print local print = print
local type = type local type = type
local rtable = table local rtable = table
local ipairs = ipairs local pairs = pairs
local capi = local capi =
{ {
awesome = awesome, awesome = awesome,
@ -218,14 +218,19 @@ function subsets(set)
end end
--- Join all tables given as parameters. --- Join all tables given as parameters.
-- This will iterate all tables and insert value from 1 to N. -- This will iterate all tables and insert all their keys into a new table.
-- Non integer keys are ignored.
-- @param args A list of tables to join -- @param args A list of tables to join
-- @return A new table containing all interger keys from the arguments. -- @return A new table containing all keys from the arguments.
function table.join(...) function table.join(...)
local ret = {} local ret = {}
for i = 1, arg.n do for i = 1, arg.n do
for k, v in ipairs(arg[i]) do rtable.insert(ret, v) end for k, v in pairs(arg[i]) do
if type(k) == "number" then
rtable.insert(ret, v)
else
ret[k] = v
end
end
end end
return ret return ret
end end