如何使用调试库与所需的lua文件的upvalues进行交互

时间:2017-11-13 01:13:24

标签: lua closures upvalue

如果我有一个Lua函数f,我可以使用f函数查看debug.getupvalue闭包中的所有upvalues。同样,如果我有一个文件foo.lua,我可以先查看upvalues,然后先使用foo = loadfile(foo) debug.getupvalue,就像使用f一样。如果我require foo.lua在那里,我可以弄清楚foo.lua关闭的上升值是什么?

1 个答案:

答案 0 :(得分: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.