|
On Sun, Nov 18, 2018 at 8:03 PM Philippe Verdy <verdy_p@wanadoo.fr> wrote:
> So "function f(x)... end" is not completely equivalent to "f= function(x) ... end": the first one declares a new local variable named "f", the second overwrites an existing variable "f" in scope, or creates a new local variable.
Are you sure? The manual (
https://www.lua.org/manual/5.3/manual.html#3.4.11 ) says it's
completely equivalent and a simple test:
Lua 5.3.3 Copyright (C) 1994-2016 Lua.org, PUC-Rio
> a=1;function tst() local b; function a() end; function b() end; function c() end; print('a',a,'b',b,'c',c,'Z'); end; print('a',a,'b',b,'c',c,'Z'); tst(); print('a',a,'b',b,'c',c,'Z');
a 1 b nil c nil Z
a function: 0x9da150 b function: 0x9da0c8 c function:
0x9bfdb8 Z
a function: 0x9da150 b nil c function: 0x9bfdb8 Z
Seems to contradict your "or creates a local variable" ( c is alive
after tst(), so it should be global )
Francisco Olarte.