lua-users home
lua-l archive

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


On Dec 28, 2010, at 5:31 PM, Steve Litt wrote:

> And the same documentation shows the generic for statement as:
> 
> for var_1, ···, var_n in explist do block end
> 
> explist is supposed to be an iterator function.

No, it's "an iterator function, a state, and an initial value for the first iterator variable."

> I have no idea how "next, t, 
> #t > 0 and #t or nil" evaluates to an iterator function.

next is the iterator function
t is the state
#t > 0 and #t or nil is the initial value for the first iterator variable

How these are used by the generic for statement is described in the pseudo code at 
http://www.lua.org/manual/5.1/manual.html#2.4.5

e