Make dbg.pretty() overloadable.
This commit is contained in:
parent
1ddfb6b29b
commit
a37cc46213
|
@ -81,6 +81,7 @@ There are several overloadable functions you can use to customize debugger.lua.
|
||||||
* `dbg.write(str)` - Write a string to the output. (Defaults to write to stdout)
|
* `dbg.write(str)` - Write a string to the output. (Defaults to write to stdout)
|
||||||
* `dbg.shorten_path(path)` - Return a shortened version of a path. (Defaults to simply return `path`)
|
* `dbg.shorten_path(path)` - Return a shortened version of a path. (Defaults to simply return `path`)
|
||||||
* `dbg.exit(err)` - Stop debugging. (Defaults to `os.exit(err)`)
|
* `dbg.exit(err)` - Stop debugging. (Defaults to `os.exit(err)`)
|
||||||
|
* `dbg.pretty(obj)' - Output a pretty print string for an object. (Defaults to a reasonable version using __tostring metamethods and such)
|
||||||
|
|
||||||
Using these you can customize the debugger to work in your environment. For instance, you can divert the I/O over a network socket or to a GUI window.
|
Using these you can customize the debugger to work in your environment. For instance, you can divert the I/O over a network socket or to a GUI window.
|
||||||
|
|
||||||
|
|
12
debugger.lua
12
debugger.lua
|
@ -290,7 +290,7 @@ local function cmd_print(expr)
|
||||||
else
|
else
|
||||||
local output = ""
|
local output = ""
|
||||||
for i = 2, results.n do
|
for i = 2, results.n do
|
||||||
output = output..(i ~= 2 and ", " or "")..pretty(results[i])
|
output = output..(i ~= 2 and ", " or "")..dbg.pretty(results[i])
|
||||||
end
|
end
|
||||||
|
|
||||||
if output == "" then output = "<no result>" end
|
if output == "" then output = "<no result>" end
|
||||||
|
@ -395,7 +395,7 @@ local function cmd_locals()
|
||||||
|
|
||||||
-- Skip the debugger object itself, "(*internal)" values, and Lua 5.2's _ENV object.
|
-- Skip the debugger object itself, "(*internal)" values, and Lua 5.2's _ENV object.
|
||||||
if not rawequal(v, dbg) and k ~= "_ENV" and not k:match("%(.*%)") then
|
if not rawequal(v, dbg) and k ~= "_ENV" and not k:match("%(.*%)") then
|
||||||
dbg_writeln(" "..COLOR_BLUE..k.. GREEN_CARET..pretty(v))
|
dbg_writeln(" "..COLOR_BLUE..k.. GREEN_CARET..dbg.pretty(v))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -517,7 +517,7 @@ dbg.writeln = dbg_writeln
|
||||||
|
|
||||||
dbg.pretty_depth = 3
|
dbg.pretty_depth = 3
|
||||||
dbg.pretty = pretty
|
dbg.pretty = pretty
|
||||||
dbg.pp = function(value, depth) dbg_writeln(pretty(value, depth)) end
|
dbg.pp = function(value, depth) dbg_writeln(dbg.pretty(value, depth)) end
|
||||||
|
|
||||||
dbg.auto_where = false
|
dbg.auto_where = false
|
||||||
dbg.auto_eval = false
|
dbg.auto_eval = false
|
||||||
|
@ -527,7 +527,7 @@ local lua_error, lua_assert = error, assert
|
||||||
-- Works like error(), but invokes the debugger.
|
-- Works like error(), but invokes the debugger.
|
||||||
function dbg.error(err, level)
|
function dbg.error(err, level)
|
||||||
level = level or 1
|
level = level or 1
|
||||||
dbg_writeln(COLOR_RED.."ERROR: "..COLOR_RESET..pretty(err))
|
dbg_writeln(COLOR_RED.."ERROR: "..COLOR_RESET..dbg.pretty(err))
|
||||||
dbg(false, level, "dbg.error()")
|
dbg(false, level, "dbg.error()")
|
||||||
|
|
||||||
lua_error(err, level)
|
lua_error(err, level)
|
||||||
|
@ -546,7 +546,7 @@ end
|
||||||
-- Works like pcall(), but invokes the debugger on an error.
|
-- Works like pcall(), but invokes the debugger on an error.
|
||||||
function dbg.call(f, ...)
|
function dbg.call(f, ...)
|
||||||
return xpcall(f, function(err)
|
return xpcall(f, function(err)
|
||||||
dbg_writeln(COLOR_RED.."ERROR: "..COLOR_RESET..pretty(err))
|
dbg_writeln(COLOR_RED.."ERROR: "..COLOR_RESET..dbg.pretty(err))
|
||||||
dbg(false, 1, "dbg.call()")
|
dbg(false, 1, "dbg.call()")
|
||||||
|
|
||||||
return err
|
return err
|
||||||
|
@ -556,7 +556,7 @@ end
|
||||||
-- Error message handler that can be used with lua_pcall().
|
-- Error message handler that can be used with lua_pcall().
|
||||||
function dbg.msgh(...)
|
function dbg.msgh(...)
|
||||||
if debug.getinfo(2) then
|
if debug.getinfo(2) then
|
||||||
dbg_writeln(COLOR_RED.."ERROR: "..COLOR_RESET..pretty(...))
|
dbg_writeln(COLOR_RED.."ERROR: "..COLOR_RESET..dbg.pretty(...))
|
||||||
dbg(false, 1, "dbg.msgh()")
|
dbg(false, 1, "dbg.msgh()")
|
||||||
else
|
else
|
||||||
dbg_writeln(COLOR_RED.."debugger.lua: "..COLOR_RESET.."Error did not occur in Lua code. Execution will continue after dbg_pcall().")
|
dbg_writeln(COLOR_RED.."debugger.lua: "..COLOR_RESET.."Error did not occur in Lua code. Execution will continue after dbg_pcall().")
|
||||||
|
|
Loading…
Reference in New Issue