[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Multiple values returned or vararg expression in numeric for loop
- From: Michal Kolodziejczyk <miko@...>
- Date: Fri, 14 Sep 2012 08:15:53 +0200
On 13.09.2012 14:10, Egor Skriptunoff wrote:
> Why this simple code
>
> for i = 1, 5 do print(i) end
>
> cannot be written in more general form ?
The only reasons I can think of are implementation optimization, and "a
heritage" - everyone is used to this kind of for syntax.
> local function f() return 1, 5 end
> for i = f() do print(i) end
You could use metalua, or parse the string yourself:
loadstring('for i='..table.concat({f()}, ',')..' do print(i) end')
Regards,
miko