[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Visibility of locals: load and loadin vs function
- From: Dirk Laurie <dpl@...>
- Date: Wed, 1 Dec 2010 22:49:53 +0200
I run 'lua foo.lua', where foo.lua contains:
A=1
local A=2
f=load('return A')
function g() return A end
print (f(),g())
The output is
1 2
I extrapolate from this example to conclude that:
1. 'load' sees no local variables from the block in which it
is executed, neither does 'loadin'.
2. 'load' can be appear anywhere in the code, with no change in
its effect, as long as the function defined by it exists
by the time that it is called.
3. 'function', on the other hand, can see local variables and its
effect therefore does depend on where in the code it stands.
Right?
Dirk