/ Published in: Lua
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
-- "Sorted by key" table iterator -- Extracted from http://www.lua.org/pil/19.3.html function pairsKeySorted(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