lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On 4 April 2018 at 04:15, Jean-Luc Jumpertz <> wrote:
> Direct enumeration can be customized by defining a "__forgen" (for generator) metamethod that shall return the 3 values needed by the generic for loop: an iterator function, a state, and the initial value of the iterator variable.
> If no "__forgen" metamethod is defined and the collection is a Lua table, direct enumeration is equivalent to calling the standard Lua library function pair().

Must be that time of the year for the __iter proposal :P

Generally the outcome is:
  - Lua used to do bare iteration but removed it
  - There are often multiple ways to iterate an object (see ipairs vs
pairs). It's limiting to pick just one.
  - You can already do it with  __call