lua-users home
lua-l archive

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

Why lua do not make them(local function xxx and local yyy= function) as the same?


Because the scope of "local yyy" doesn't begin until the next statement. Makes things like this possible:

local temp = a + b
local temp = temp * 2

Where as if they were the same the second line would throw a arithmetic on nil error. (or even worse, that position may be entirely uninitialized).

To special case functions would be very difficult for the parser (and confusing), as you may have a scenario like this:

local temp = function() return temp end or temp

Where each use of temp is a different one.

- Alex