|
|
||
|
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). So both (or all if you create more) counters share i, which indeed increments from 1 to 5, the second number printed increments only for the separate calls to either c1 or c2. HTH Thijs From: [email protected] [mailto:[email protected]] On Behalf Of Minh Ngo Hello, there is an example in Programming in Lua chapter 6.1 about closures. I made a small change in the example to see if the results are the same, but they are not; |