2021-06-11 11:47:29 -07:00
|
|
|
-- Localize globals
|
|
|
|
local _G, debug, getfenv, table, tostring = _G, debug, getfenv, table, tostring
|
|
|
|
|
2021-06-17 10:45:08 -07:00
|
|
|
-- Set environment
|
|
|
|
local _ENV = {}
|
|
|
|
setfenv(1, _ENV)
|
|
|
|
|
2021-05-04 07:18:46 -07:00
|
|
|
function variables(stacklevel)
|
|
|
|
stacklevel = (stacklevel or 1) + 1
|
|
|
|
local locals = {}
|
|
|
|
local index = 1
|
|
|
|
while true do
|
|
|
|
local name, value = debug.getlocal(stacklevel, index)
|
|
|
|
if not name then break end
|
|
|
|
table.insert(locals, {name, value})
|
|
|
|
index = index + 1
|
|
|
|
end
|
|
|
|
local upvalues = {}
|
|
|
|
local func = debug.getinfo(stacklevel).func
|
|
|
|
local fenv = getfenv(func)
|
|
|
|
index = 1
|
|
|
|
while true do
|
|
|
|
local name, value = debug.getupvalue(func, index)
|
|
|
|
if not name then break end
|
|
|
|
table.insert(upvalues, {name, value})
|
|
|
|
index = index + 1
|
|
|
|
end
|
|
|
|
return {
|
|
|
|
locals = locals,
|
|
|
|
upvalues = upvalues,
|
|
|
|
fenv = fenv,
|
|
|
|
fenv_global = fenv == _G
|
|
|
|
}
|
2021-03-31 13:15:38 -07:00
|
|
|
end
|
|
|
|
|
2021-05-04 07:18:46 -07:00
|
|
|
function stack(stacklevel)
|
|
|
|
stacklevel = (stacklevel or 1) + 1
|
|
|
|
local stack = {}
|
|
|
|
while true do
|
|
|
|
local info = debug.getinfo(stacklevel, "nfSlu")
|
|
|
|
if not info then
|
|
|
|
break
|
|
|
|
end
|
|
|
|
info.func = tostring(info.func)
|
2021-06-11 11:28:27 -07:00
|
|
|
info.variables = variables(stacklevel)
|
2021-05-04 07:18:46 -07:00
|
|
|
stack[stacklevel - 1] = info
|
|
|
|
stacklevel = stacklevel + 1
|
|
|
|
end
|
|
|
|
return stack
|
2021-06-17 10:45:08 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
-- Export environment
|
|
|
|
return _ENV
|