[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Lua closure and non-local variables
- From: Roberto Ierusalimschy <roberto@...>
- Date: Fri, 16 Mar 2012 13:07:01 -0300
> When you call newCounter(), you'll create a new instance of j (the
> definition is within newCounter), but reuse the existing i (its definition
> is outside newCounter).
For explanatory purposes, we may think that each time the program
"executes" 'local x' it creates a new 'x' variable. Your code executes
'local i' only once, so there is only one 'i'.
-- Roberto