[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Forward declarations in modules
- From: Nick Gammon <nick@...>
- Date: Thu, 7 Sep 2006 13:32:19 +1000
On 07/09/2006, at 1:19 PM, Mark Edgar wrote:
the local statement creates a new local
This code is interesting:
-------
local a = 10
function f ()
  print (a)
end -- f
local a = 20
function g ()
  print (a)
end -- g
local a = 30
f ()  --> 10
g ()  --> 20
--------
It seems that there are actually 3 copies of "a" here, with different  
values. By the time I call f and g the most recent a is 30, however  
they seem to be "bound" to the local declarations earlier up.
How does Lua distinguish each "a" from each other? Judging by the  
earlier error message it makes them upvalues of the functions as it  
hits the function declarations.
- Nick