lua-users home
lua-l archive

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


Lua 5.0 beta does produce
1
2
12
with the code below. Of course earlier versions of Lua will complain in various ways since they lack lexical scoping.

Fancy stuff.

Russ

On Monday, April 7, 2003, at 12:25  PM, RLake@oxfam.org.uk wrote:


Russell: cut and pasted

Lua 5.0  Copyright (C) 1994-2003 Tecgraf, PUC-Rio
function outer()
     local x = 0
     function inner()
             x = x + 1
             print(x)
     end
     inner() -- should print "1"
     return inner
end

x = 12
f = outer()
1
f() -- what does this do?  runtime error?
2
print(x) -- I assume this prints "12"
12