Search code examples
luaclosuresupvalue

how to use the debug library to interact with a required lua file's upvalues


If I have a Lua function f I can look at all the upvalues in f's closure by using the debug.getupvalue function. Similarly if I have a file foo.lua I can look at the upvalues by first doing foo = loadfile(foo) then using debug.getupvalue in the same way that you would for f. If I require foo.lua is there anyway I can figure out what the upvalues for the closure of foo.lua are?


Solution

  • The module loaded by require is not preserved by require's standard loaders. Only the return value from the execution of that module is preserved.

    So while you can inspect any upvalues for any function exported by the module, you cannot inspect upvalues that are only accessed by non-accessible functions.