debug.getstack retrieves a value from the call stack. This allows you to read local variables and temporary values from any level of the current call stack.
local function level2() local secret = "hidden value" level1()endlocal function level1() -- Get the 'secret' variable from level2 local value = debug.getstack(2, 1) print(value) -- "hidden value"endlevel2()