Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- lines = {
- apple = 3,
- banana = 2,
- carrot = 1}
- for name, line in pairsByKeys(lines) do
- print(name, line)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement