lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


local function bar()
end

is just sugar for

local bar = function()
end

Function definitions are just like regular Lua statements; they get
executed in order.  Consider this code:

print(bar)
local function bar()
end

Or better yet, this code:

print(a)
local a = 5

What happens in each case?

-Rob

On Mon, 23 Aug 2010 23:11:15 +0200
Andreas Matthias <andreas.matthias@gmail.com> wrote:

> Calling foo() from the following module results in an
> "attempt to call global 'bar' (a nil value)":
> 
> module(...)
> 
> function foo()
>    bar()
> end
> 
> local function bar()
> end
> 
> 
> But it's running through if I
>  a) define bar() before foo() or
>  b) define bar() to be non-local.
> 
> What's going on here? I don't understand it.
> 
> 
> Ciao
> Andreas
> 

Attachment: signature.asc
Description: PGP signature