Anonymous

Module:FunList/Iterators: Difference between revisions

From Melvor Idle
Finally added support for ipairs
No edit summary
(Finally added support for ipairs)
Line 33: Line 33:
end
end


function Enumerator:getEnumerator()
function Enumerator:getEnumerator(isArray)
error('Not implemented in base class.')
error('Not implemented in base class.')
end
end
Line 40: Line 40:
function Enumerator:overridePairs(startIndex)
function Enumerator:overridePairs(startIndex)
-- Get or create clean enumerator. This ensures the state is 0.
-- Get or create clean enumerator. This ensures the state is 0.
local enum = self:getEnumerator()
local enum = self:getEnumerator(isArray)
enum.current = nil
enum.current = nil
enum.index = startIndex
enum.index = startIndex
enum.isArray = startIndex == 0
local function iterator(t, k)
local function iterator(t, k)
if enum:moveNext() == true then
if enum:moveNext() == true then
2,875

edits