lua-users home
lua-l archive

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


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