|
On Sat, Mar 3, 2018 at 8:23 PM Milind Gupta <milind.gupta@gmail.com> wrote:Hi,I have the following code snippet:--------------------------------------------------- local function add(a,b)return a + bendprint(_ENV["add"],_G["add"],add) for k,v in pairs(_ENV) doprint(k,v)endprint("-------------------")print(debug.getupvalue(debug.getinfo(1).func,1)) ------------------------------------------------------ I am trying to find out where "add" function is stored. Since it is defined local it was not there in _ENV and _G. I also cannot find it in the upvalues. Where is the function?Thanks,MilindThere's no way to dynamically look up locals via table syntax, because they aren't stored in a table. Locals are stored directly in the internal registers used by the VM. Without the debug library, the only way to access a local is by directly naming it in the code.
That said, debug.getlocal() does exist [1], but this does not allow lookup by name, only by the internal number. You would have to enumerate all locals to find the one you want.
[1] https://www.lua.org/manual/5.3/manual.html#pdf-debug. getlocal