49
edits
({{luaapi}}) |
|||
| Line 42: | Line 42: | ||
function pairsByKeys (t, f) | function pairsByKeys (t, f) | ||
local a = {} | |||
for n in pairs(t) do table.insert(a, n) end | |||
table.sort(a, f) | |||
local i = 0 -- iterator variable | |||
local iter = function () -- iterator function | |||
i = i + 1 | |||
if a[i] == nil then return nil | |||
else return a[i], t[a[i]] | |||
end | |||
end | |||
return iter | |||
end | end | ||
| Line 58: | Line 58: | ||
for title,value in pairsByKeys(randomtable) do | for title,value in pairsByKeys(randomtable) do | ||
DEFAULT_CHAT_FRAME:AddMessage(title..", "..value); | |||
end | end | ||
This will print all the variables in randomtable alphabetically! | This will print all the variables in randomtable alphabetically! | ||