lua-users home
lua-l archive

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


But "local f;" make 'f' be a global variable.

On Wed, Dec 31, 2008 at 03:17, Javier Guerra <javier@guerrag.com> wrote:
On Tue, Dec 30, 2008 at 2:14 PM, Linker <linker.m.lin@gmail.com> wrote:
> 1:
> local function n() print(n);n();end
> n()
> infinite loop
> 2:
> local n2=function() print(n2);n2();end
> n2()
> output: nil
> error:attempt to call global 'n2' (a nil value)
> Why?
> --
> Regards,
> Linker Lin
> linker.m.lin@gmail.com
>

from the manual:
2.5.9 - Function Definitions

.....snip...
The statement
    local function f () body end

 translates to
    local f; f = function () body end

not to
    local f = function () body end

 (This only makes a difference when the body of the function contains
references to f.)


--
Javier



--
Regards,
Linker Lin
linker.m.lin@gmail.com