Upvalues
Upvalues
An upvalue of a local variable from an enclosing function is created by adding a % prefix to the variable name:
%localvarname
An upvalue is a variable whose value is frozen when the function wherein the upvalue appears is instantiated. The name used in an upvalue may be the name of any variable visible at the point where the function is defined, that is, global variables and local variables from the immediately enclosing function.
When the upvalue is a table, only the reference to that table (which is the value of the upvalue) is frozen; the table contents can be changed at will. This is a technique for having writable but private state attached to functions.