lua-users home
lua-l archive

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


in Lua 4.0 running a function like this:
 
function A(x)
  return function () return %x end
end
 
made each time a different function with an upvalue x "embedded" in it, making a function closure.
 
What is the semantics of Lua5 scoping in such case?
 
function A(x)
  return function () return x end
end
 
as far as I understand you can freely access the local vars of the outer scope, including changing of their values. But if such second level function (as in this case) is returned and called afterwards the outer scope in which it was defined is gone.
What I mean is this: are this variables accessed from inner function are in fact upvalues, that got rid of %? And what about old upvalues? Are they still available for backward compatibility?
I am new to such concept as closures. I've never delt with functional languages before.