local p =
local function __genOrderedIndex(t) local orderedIndex = for key in pairs(t) do table.insert(orderedIndex, key) end table.sort(orderedIndex) return orderedIndexend
local function orderedNext(t, state) -- Equivalent of the next function, but returns the keys in the alphabetic -- order. We use a temporary ordered key table that is stored in the -- table being iterated.
local key = nil if state
state then key = t.__orderedIndex[i + 1] end end end
if key then return key, t[key] end
-- no more value to return, cleanup t.__orderedIndex = nil returnend
function p.orderedPairs(t) -- Equivalent of the pairs function on tables. Allows to iterate in order. return orderedNext, t, nilend
return p