mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Update rfcs/generalized-iteration.md
Co-authored-by: dcope-rbx <91100513+dcope-rbx@users.noreply.github.com>
This commit is contained in:
parent
b5df447e5d
commit
57b7d723bf
1 changed files with 1 additions and 1 deletions
|
@ -46,7 +46,7 @@ end
|
||||||
|
|
||||||
### __iter
|
### __iter
|
||||||
|
|
||||||
To support self-iterating objects, we modify the iteration protocol as follows: instead of simply expanding the result of expression `iter` into three variables (`gen`, `state` and `index`), we check if the first result has an `__iter` metamethod (which can be the case if it's a table, userdata or another composit object (e.g. a record in the future). If it does, the metamethod is called with `gen` as the first argument, and the returned three values replace `gen`/`state`/`index`. This happens *before* the loop:
|
To support self-iterating objects, we modify the iteration protocol as follows: instead of simply expanding the result of expression `iter` into three variables (`gen`, `state` and `index`), we check if the first result has an `__iter` metamethod (which can be the case if it's a table, userdata or another composite object (e.g. a record in the future). If it does, the metamethod is called with `gen` as the first argument, and the returned three values replace `gen`/`state`/`index`. This happens *before* the loop:
|
||||||
|
|
||||||
```lua
|
```lua
|
||||||
if getmetatable(gen) and getmetatable(gen).__iter then
|
if getmetatable(gen) and getmetatable(gen).__iter then
|
||||||
|
|
Loading…
Add table
Reference in a new issue