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?
Asked
Active
Viewed 288 times
2

Ace shinigami
- 1,374
- 2
- 12
- 25
-
You can also assign a value to upvalue by `debug.setupvalue` and join two upvalues by `debug.upvaluejoin` – Egor Skriptunoff Nov 13 '17 at 01:22
-
very true, in fact in my specific case I'm trying to use debug.`upvaluejoin` – Ace shinigami Nov 13 '17 at 01:31
-
@Julian: What is your question? Your question text doesn't seem to state the question. – Nicol Bolas Nov 13 '17 at 02:32
1 Answers
2
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.

Nicol Bolas
- 449,505
- 63
- 781
- 982