[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Non local variables not becoming global?
- From: Saptarshi Guha <saptarshi.guha@...>
- Date: Mon, 18 Oct 2010 22:23:24 -0700
I have a question about locals for some constructs.
Suppose I have
f1 = function(a)
local x = 1
for i=1,3 do
Then, when f2 is called, y is created in the global scope. To avoid
this i can write
just below the 'local x=1' line.
Is there anyway to force chunks to create variable in the current context rather
than in global when local is not specified?
So that in the above, print(y) would display nil?
(I'm using 5.1, does the _ENV (in 5.2) help in any way?)