lua-users home
lua-l archive

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


Why Lua 5.1 allows to define local variables more than once and not throws error?
local a = 1
local a = a or 2
print(a) -- will print "1"

function f(a)
  -- we don't see it, but variable `a` is already defined in function's scope
  -- and now we still can define local variable with same name `a`
  local a = a or 4
  print(a)
end
f(3) -- will print "3"

--
rafis