[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: modules and locals
- From: Andreas Matthias <andreas.matthias@...>
- Date: Tue, 24 Aug 2010 00:19:22 +0200
Drake Wilson wrote:
> Quoth Andreas Matthias <andreas.matthias@gmail.com>, on 2010-08-23 23:11:15 +0200:
>> function foo()
>> bar()
>> end
>>
>> local function bar()
>> end
> [...]
>> What's going on here? I don't understand it.
>
> The scope of a lexical local starts after its declaration and extends
> to the end of the containing block. A local function is just like any
> other local variable in that regard.
Ok, that's reasonable. But why does lua find bar() if it is
defined as a non-local? Why doesn't it need a kind of
function prototype then?
> One way of doing what you seem
> to want is to declare « local bar » above, then use « bar = function()
> ... end ». Another, more obvious way would be to just let it be a
> 'global' (in the current environment table).
I see. So the following works:
local bar
function foo()
bar()
end
bar = function () end
But what's happening if I change this to:
local bar
function foo()
bar()
end
local bar = function () end
These two `bar's seem not to be the same. Why?
Ciao
Andreas