debug.getupvalue
Lua function debug.getupvalue Summary Returns the name and value of an upvalue Prototype `name, value = debug.getupvalue (level, upvalue)` Description `Similar to debug.getlocal, returns the names and values of the upvalues for the nominated function. See also debug.setupvalue.
    function newCounter ()
      local n = 0
      return function ()  -- anonymous function
        n = n + 1
        return n
        end -- function
    end -- newCounter

    c = newCounter ()
    c ()  -- count a couple of times
    c ()

    -- show upvalues in c

    local i = 1

    repeat
      name, val = debug.getupvalue (c, i)
      if name then
        print ("index", i, name, "=", val)
        i = i + 1
      end -- if
    until not name

     -->

     index 1 n = 2
In this example the function c is a closure (with associated upvalue "n"). NOTE: Lua does not let you see or change upvalues for C functions (eg. string.gfind).` See Also ... Topics Lua base functions Lua bc (big number) functions Lua bit manipulation functions Lua coroutine functions Lua debug functions Lua io functions Lua math functions Lua os functions Lua package functions Lua PCRE regular expression functions Lua script extensions Lua string functions Lua table functions Lua utilities Scripting Lua functions debug.debug (Enters interactive debugging) debug.getfenv (Returns the environment of an object) debug.gethook (Returns the current hook settings) debug.getinfo (Returns a table with information about a function) debug.getlocal (Returns name and value of a local variable) debug.getmetatable (Returns the metatable of the given object) debug.getregistry (Returns the registry table) debug.setfenv (Sets the environment of an object) debug.sethook (Sets a debug hook function) debug.setlocal (Sets the value of the local variable) debug.setmetatable (Sets the metatable for an object) debug.setupvalue (Sets an upvalue for a function) debug.traceback (Returns a string with a traceback of the stack call) (Help topic: lua=debug.getupvalue) Documentation contents page