lua-users home
lua-l archive

Closures

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


I'm getting some results I was not expecting with this code.
functionList = {}
for i=1, 10 do
 functionList[ i ] = function()
print( i ) end
end
for i=1, 10 do
 functionList[ i ]()
end
I get ten 10's printed out. As I understand closures I would have expected 1 to 10. Could someone enlighten me as to what is wrong?
Thanks.
Jack

AltStyle によって変換されたページ (->オリジナル) /