Replies: 1 comment 2 replies
-
This is already supported, Nelua supports local function iter(max: integer): (auto, integer, integer)
local function iter_next(max: integer, i: integer): (boolean, integer)
i = i + 1
if i >= max then
return false, 0
end
return true, i
end
return iter_next, max, -1
end
for i in iter(10) do
print(i) -- outputs: 0 1 2 3 4 5 6 7 8 9
end You can also embed a more complex state inside the iterator, check In the compiler sources, the |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Since closure is in plan, I think it is possible to support a lightware coroutine?
I mean, transform this function
to
why perfer this approach since we already have the stackful coroutine?
to make iterator easier without add too much runtime cost.
the state record generation should be able to share same logic in future closure implemention, the only challenge is how to transform loop and other control flow to this style
Beta Was this translation helpful? Give feedback.
All reactions