lua-users home
lua-l archive

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


On Thu, Jun 17, 2021 at 5:35 PM Domingo Alvarez Duarte
<mingodad@gmail.com> wrote:
> Isn't this the general pattern in Lua to always create a new variable
> and shadow any existing one with the same name, without telling anything
> to the user ?

function x() does not create a new variable, it uses a created one (
either local or global, although you may consider the global one as
"created" )

The problem is:
----------
$ cat u.lua && lua u.lua
local x <const> = nil
function x() end

local y <const> = nil
y = function() end

lua: u.lua:5: attempt to assign to const variable 'y'
-------
Coupled with the definition in 3.4.11
---
The statement
     function f () body end
translates to
     f = function () body end
---
Which mean they should both pass or fail. No new vars created by the
function lines, which will be the case if "local function" where used.

Francisco Olarte.