『Programing in Lua』第3部CH 18-CH 19
3931 ワード
CH 18:数学ライブラリ
CH 19:tableライブラリ
tLines = {
luaH_set = 10,
luaH_get = 24,
luaH_present = 48
}
function pairsByKey(t, f) --f
local a = {}
for n in pairs(t) do a[#a + 1] = n end
table.sort(a, f)
local i = 0
return function()
i = i + 1
return a[i], t[a[i]]
end
end
for name, line in pairsByKey(tLines) do
print(name, line)
end
--
-- :
function rconcat(l)
if type(l) ~= "table" then return l end
local res = {}
for i = 1, #l do
res[i] = rconcat(l[i])
end
return table.concat(res)
end
t = { { "a", {" nice"} }, " and", { {" long"}, {" list!"} } }
print(rconcat(t))