Anonymous

Module:FunList/Iterators: Difference between revisions

From Melvor Idle
no edit summary
No edit summary
No edit summary
Line 36: Line 36:


-- Hooks the moveNext function into the Lua 'pairs' function
-- Hooks the moveNext function into the Lua 'pairs' function
function Enumerator:overridePairs()
function Enumerator:overridePairs(startIndex)
self.index = nil
-- Get or create clean enumerator
self.current = nil
local enum = self:getEnumerator()
enum.index = startIndex
enum.current = nil
local function iterator(t, k)
local function iterator(t, k)
if self:moveNext() == true then
if enum:moveNext() == true then
return self.index, self.current
return enum.index, enum.current
end
end
return nil, nil
return nil, nil
end
end
return iterator, self, nil
return iterator, enum, startIndex
end
end


2,875

edits