lua-users home
lua-l archive

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

Rich Artym wrote:

> incrementfirstfoo() -- prints 11.1 instead of 10.1 if it were closed

This is exactly how Lua lexical scoping is supposed to
work -- just like Scheme lexical scoping (i.e., "true"
lexical scoping).  I believe in some other languages
upvalues work like you're thinking of (i.e., they get turned
into local variables internal to the function).  This can
still be done in Lua, but it must be done explicitly:

local foo = 10

function bar()
  local foo = foo
end -- bar

Actually, many of the benefits of lexical scoping are only
available in languages like Lua with true upvalues.