Search code examples
functionlualocal-variables

Lua: Get Locals Outside of Function From A Function


I'm wanting to get all locals in the enviroment (debug.getlocal) when i call a certain function (getlenv), but when i call this function it only gets the local variables inside of the function not outside of the function. Is this possible? if so how?

Code i have right now

function getlenv()
    local i = 1
    repeat
        local k, v = debug.getlocal(1, i)
        if k then
            print(k, v)
            i = i + 1
        end
    until nil == k
end

getlenv()

Solution

  • Solved, i was just being dumb, just had to change local k, v = debug.getlocal(1, i) to local k, v = debug.getlocal(2, i) to get the locals outside of the function o_0