<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.runerealm.org/index.php?action=history&amp;feed=atom&amp;title=Module%3AUtils</id>
	<title>Module:Utils - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.runerealm.org/index.php?action=history&amp;feed=atom&amp;title=Module%3AUtils"/>
	<link rel="alternate" type="text/html" href="https://wiki.runerealm.org/index.php?title=Module:Utils&amp;action=history"/>
	<updated>2026-04-30T18:59:21Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.41.1</generator>
	<entry>
		<id>https://wiki.runerealm.org/index.php?title=Module:Utils&amp;diff=35223&amp;oldid=prev</id>
		<title>Alex: Created page with &quot; -- Ordered table iterator, allow to iterate on the natural order of the keys of a -- table.  local p = {}  function __genOrderedIndex( t )     local orderedIndex = {}     for key in pairs(t) do         table.insert( orderedIndex, key )     end     table.sort( orderedIndex )     return orderedIndex end   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...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.runerealm.org/index.php?title=Module:Utils&amp;diff=35223&amp;oldid=prev"/>
		<updated>2024-10-16T23:13:23Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot; -- Ordered table iterator, allow to iterate on the natural order of the keys of a -- table.  local p = {}  function __genOrderedIndex( t )     local orderedIndex = {}     for key in pairs(t) do         table.insert( orderedIndex, key )     end     table.sort( orderedIndex )     return orderedIndex end   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...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&lt;br /&gt;
-- Ordered table iterator, allow to iterate on the natural order of the keys of a&lt;br /&gt;
-- table.&lt;br /&gt;
&lt;br /&gt;
local p = {}&lt;br /&gt;
&lt;br /&gt;
function __genOrderedIndex( t )&lt;br /&gt;
    local orderedIndex = {}&lt;br /&gt;
    for key in pairs(t) do&lt;br /&gt;
        table.insert( orderedIndex, key )&lt;br /&gt;
    end&lt;br /&gt;
    table.sort( orderedIndex )&lt;br /&gt;
    return orderedIndex&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
function orderedNext(t, state)&lt;br /&gt;
    -- Equivalent of the next function, but returns the keys in the alphabetic&lt;br /&gt;
    -- order. We use a temporary ordered key table that is stored in the&lt;br /&gt;
    -- table being iterated.&lt;br /&gt;
 &lt;br /&gt;
    local key = nil&lt;br /&gt;
    --print(&amp;quot;orderedNext: state = &amp;quot;..tostring(state) )&lt;br /&gt;
    if state == nil then&lt;br /&gt;
        -- the first time, generate the index&lt;br /&gt;
        t.__orderedIndex = __genOrderedIndex( t )&lt;br /&gt;
        key = t.__orderedIndex[1]&lt;br /&gt;
    else&lt;br /&gt;
        -- fetch the next value&lt;br /&gt;
        for i = 1,table.getn(t.__orderedIndex) do&lt;br /&gt;
            if t.__orderedIndex[i] == state then&lt;br /&gt;
                key = t.__orderedIndex[i+1]&lt;br /&gt;
            end&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
    if key then&lt;br /&gt;
        return key, t[key]&lt;br /&gt;
    end&lt;br /&gt;
 &lt;br /&gt;
    -- no more value to return, cleanup&lt;br /&gt;
    t.__orderedIndex = nil&lt;br /&gt;
    return&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
function p.opairs(t)&lt;br /&gt;
    -- Equivalent of the pairs() function on tables. Allows to iterate&lt;br /&gt;
    -- in order&lt;br /&gt;
    return orderedNext, t, nil&lt;br /&gt;
end&lt;br /&gt;
 &lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Alex</name></author>
	</entry>
</feed>