2,875
edits
No edit summary |
No edit summary |
||
Line 62: | Line 62: | ||
function TableEnumerator.new(tbl) | function TableEnumerator.new(tbl) | ||
local self = setmetatable(Enumerator.new(), TableEnumerator) | local self = setmetatable(Enumerator.new(), TableEnumerator) | ||
self.tbl = tbl | self.tbl = tbl or {} -- Allow creation of empty enumerable | ||
self.state = 0 | self.state = 0 | ||
Line 128: | Line 127: | ||
self.state = 1 | self.state = 1 | ||
self.position = 0 | self.position = 0 | ||
self.enumerator = self.source:getEnumerator() | self.enumerator = self.source:getEnumerator(self.isArray) | ||
end | end | ||
Line 172: | Line 171: | ||
self.state = 1 | self.state = 1 | ||
self.position = 0 | self.position = 0 | ||
self.enumerator = self.source:getEnumerator() | self.enumerator = self.source:getEnumerator(self.isArray) | ||
end | end | ||
Line 220: | Line 219: | ||
if self.state == 0 then | if self.state == 0 then | ||
self.position = 0 | self.position = 0 | ||
self.enumerator = self.source:getEnumerator() | self.enumerator = self.source:getEnumerator(self.isArray) | ||
self.state = -3 -- signal to get (first) nested enumerator | self.state = -3 -- signal to get (first) nested enumerator | ||
end | end | ||
Line 245: | Line 244: | ||
if not isType(sourceTable, Enumerator) then | if not isType(sourceTable, Enumerator) then | ||
-- We need to turn the nested table into an enumerator | -- We need to turn the nested table into an enumerator | ||
self.sourceEnumerator = TableEnumerator.new(sourceTable):getEnumerator() | self.sourceEnumerator = TableEnumerator.new(sourceTable) | ||
:getEnumerator(self.isArray) | |||
else | else | ||
self.sourceEnumerator = sourceTable | self.sourceEnumerator = sourceTable |
edits