EWD, which stands for Error Warning Debugging, is a Lua(JIT) module which aims to be a fundamental component of my methodology to deal with error handling, warning and debugging. At the moment, LuaJIT is the only target.
Aimed features:
- Ability to merge re-propagated stack traces.
- A propagating warning system similar to error callbacks.
- API to inspect call stack and data, e.g. at a breakpoint.
- Ability to analyze and estimate memory usage of the Lua state.
- Ability to dump data about the Lua state for deferred inspection, e.g. when a third-party encounters an error or a bug.
API
Warning System
Warnings can be propagated just like errors, at the exception that they do not interrupt execution. As for errors, the warning message doesn't have to be a string.
ewd.warn(message [, level])
Similar to error, but for warnings. The warning is propagated to the last enclosing cwpcall warning handler (or the root handler). The execution is not interrupted.
ewd.wpcall(f, ...)
Similar to pcall, but the error caught is propagated as a warning.
ewd.cwpcall(f, err_handler, warn_handler, ...)
Similar to xpcall, but warn_handler
is a warning handler that will catch
warnings.
Callbacks:
err_handler(msg)
warn_handler(msg)
If err_handler
is the "warn"
string, the error will be propagated as a
warning to the handler above the current warning handler (warn_handler
).
Note: If the warning handler raises an error, it will be caught by the error handler.
ewd.warning_handler
The root warning handler called when there is no enclosing cwpcall.
The default handler writes to stderr. It can be replaced.