lua-users home
lua-l archive

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




On Mon, Sep 15, 2014 at 9:20 AM, Luiz Henrique de Figueiredo <lhf@tecgraf.puc-rio.br> wrote:
> for i=0,2 do
>     local i_store = i
>     local a = function() end;
>     print(a);
> end

You need to use i inside the function to create different closures:

for i=0,2 do
    local a = function() local _=i end
    print(a)
end

But why do you need different functions that do the same thing?
(or should I say same nothing? :-)


Sure enough and it is a reminder that I'm not at the point where I can answer without checking my work[1], even on something I think is simple.

Lua must be checking to see if upvalues are referenced, then?

--Andrew
.