lua-users home
lua-l archive

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


On Mon, May 24, 2010 at 5:26 PM, Stuart P. Bentley
<stuart@testtrack4.com> wrote:
> Going from a post Joonas just made, it should actually read like this:
>
> A for statement like
>
>     for var_1, ···, var_n in explist do block end
>
> is equivalent to the code:
>
>     do
>       local f, s, var = explist
>
>       --proposed addition
>       if type(f)~= "function" and not metatable(f).__call then
>         local meta_f = metatable(f).__iter
>         if not meta_f and type(f)=="table" then meta_f = pairs
>         if meta_f then f, s, var = meta_f(f) end
>       end
>
>       while true do
>         local var_1, ···, var_n = f(s, var)
>         var = var_1
>         if var == nil then break end
>         block
>       end
>     end
>
> (I'd forgotten that __call could be used to replicate the non-factory
> version of __iter.)
>

Shouldn't unpack(var) be passed to meta_f? Otherwise you can't do
factories that take multiple arguments.

~Jonathan