lua-users home
lua-l archive

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


>Why can't we use something like this in Lua ?
>
>local a = 1
>function b()
>	local c = function()
>		print(%%a)
>	end
>end
>
>It is surely strange, but by the upvalues definition (the constant value of
>a variable in the moment the function was defined (right??)) shouldn't
>constructions like this be possible ?
>
>... or function c only gets defined when we call b ?

Yes, that's the main point in understanding visibility and upvalues: c only
gets defined when b is run.

>couldn't lua handle this automatically ?:
>
>local a = 1
>function b()
>local a = %a
>	local c = function()
>		print(%a)
>	end
>end

Yes, it could. There has been some heated discussion about this in lua-l.
See the archives.
--lhf