30 lines
551 B
Lua
30 lines
551 B
Lua
-- Much thanks to https://stackoverflow.com/a/2835433
|
|
|
|
local self = {}
|
|
|
|
function self.locals()
|
|
local variables = {}
|
|
local idx = 1
|
|
while true do
|
|
local ln, lv = debug.getlocal(2, idx)
|
|
if ln == nil then break end
|
|
variables[ln] = lv
|
|
idx = 1 + idx
|
|
end
|
|
return variables
|
|
end
|
|
|
|
function self.upvalues()
|
|
local variables = {}
|
|
local idx = 1
|
|
local func = debug.getinfo(2, "f").func
|
|
while true do
|
|
local ln, lv = debug.getupvalue(func, idx)
|
|
if ln == nil then break end
|
|
variables[ln] = lv
|
|
idx = 1 + idx
|
|
end
|
|
return variables
|
|
end
|
|
|
|
return self |