mirror of
https://github.com/appgurueu/modlib.git
synced 2024-11-22 07:13:45 +01:00
Remove debug module
This commit is contained in:
parent
5a8978f93d
commit
83ff2728e3
@ -277,10 +277,6 @@ This is best left explicit. First, you shouldn't be using numbered field keys if
|
||||
4. [`json`](https://json.org)
|
||||
* Not recommended
|
||||
|
||||
## `debug`
|
||||
|
||||
`modlib.debug` offers utilities dumping program state in tables.
|
||||
|
||||
### `variables(stacklevel)`
|
||||
|
||||
Dumps local variables, upvalues and the function environment of the function at the given stacklevel (default `1`).
|
||||
|
53
debug.lua
53
debug.lua
@ -1,53 +0,0 @@
|
||||
-- Localize globals
|
||||
local _G, debug, getfenv, table, tostring = _G, debug, getfenv, table, tostring
|
||||
|
||||
-- Set environment
|
||||
local _ENV = {}
|
||||
setfenv(1, _ENV)
|
||||
|
||||
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
|
||||
}
|
||||
end
|
||||
|
||||
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)
|
||||
info.variables = variables(stacklevel)
|
||||
stack[stacklevel - 1] = info
|
||||
stacklevel = stacklevel + 1
|
||||
end
|
||||
return stack
|
||||
end
|
||||
|
||||
-- Export environment
|
||||
return _ENV
|
Loading…
Reference in New Issue
Block a user