mirror of
https://github.com/luau-lang/luau.git
synced 2025-05-04 10:33:46 +01:00
Update generalized-iteration.md
This commit is contained in:
parent
c031471260
commit
37544bffed
1 changed files with 2 additions and 0 deletions
|
@ -73,6 +73,8 @@ end
|
||||||
|
|
||||||
Luau compiler already emits a bytecode instruction, FORGPREP*, to perform initial loop setup - this is where we can evaluate `__iter` as well.
|
Luau compiler already emits a bytecode instruction, FORGPREP*, to perform initial loop setup - this is where we can evaluate `__iter` as well.
|
||||||
|
|
||||||
|
Naturally, this means that if the table has `__iter` metamethod and you need to iterate through the table fields instead of using the provided metamethod, you can't rely on the general iteration scheme and need to use `pairs`. This is similar to other parts of the language, like `t[k]` vs `rawget(t, 'k')`, where the default behavior is overrideable but a library function can help peek behind the curtain.
|
||||||
|
|
||||||
### Default table iteration
|
### Default table iteration
|
||||||
|
|
||||||
If the argument is a table and it does not implement `__iter` metamethod, we treat this as an attempt to iterate through the table using the builtin iteration order.
|
If the argument is a table and it does not implement `__iter` metamethod, we treat this as an attempt to iterate through the table using the builtin iteration order.
|
||||||
|
|
Loading…
Add table
Reference in a new issue