mirror of
https://github.com/CPunch/Cosmo.git
synced 2024-11-05 08:10:05 +00:00
CPunch
e5eca7bed6
__iter and __next are now reserved IStrings, OP_NEXT and OP_ITER have also been added. A new token (TOKEN_IN) has been added to the lexer. The parser now supports the for each loop (for i, ... in <object> do ... end). savedPushed has been removed from the CCompilerState struct.
22 lines
377 B
Plaintext
22 lines
377 B
Plaintext
proto Range
|
|
function __init(self, x)
|
|
self.max = x
|
|
end
|
|
|
|
function __iter(self)
|
|
self.i = 0
|
|
return self
|
|
end
|
|
|
|
function __next(self)
|
|
if self.i >= self.max then
|
|
return nil // exit iterator loop
|
|
end
|
|
|
|
return self.i++, self.i
|
|
end
|
|
end
|
|
|
|
for i, x in Range(10) do
|
|
print("was " .. i .. ", now " .. x)
|
|
end |