lua-users home
lua-l archive

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


Tim Hunter wrote:

The program works the way I expect it to, except that it
does not list the values of TESTUP1 and TESTUP2.

This is because the function test doesn't "close over"
TESTUP1 and TESTUP2.  For a variable to be an upvalue to a
function, it has to be used somewhere in that function
(http://www.lua.org/manual/5.1/manual.html#2.6):

# A local variable used by an inner function is called an
# upvalue, or external local variable, inside the inner
# function.

Your test program will print the names and values of TESTUP1
and TESTUP2 if, for instance, the test function includes
something like

 TESTUP1, TESTUP2 = TESTUP1, TESTUP2

--
Aaron
http://arundelo.com/