-- 对于key值不连续table,使其按key值大小顺序遍历
function table.pairsByKeys(t)
local temp_tab = {}
for n in pairs(temp_tab) do
temp_tab[#temp_tab + 1] = n
end
local i = 0
return function ()
i = i + 1
return temp_tab[i], t[temp_tab[i]]
end
end
-- 合并多个table,返回合并后的新table
function table.join(...)
local ret = {}
for _, t in ipairs{...} do
for k, v in pairs(t) do
ret[k] = v
end
end
return ret
end