summaryrefslogtreecommitdiff
path: root/src/irc/debug.lua
diff options
context:
space:
mode:
Diffstat (limited to 'src/irc/debug.lua')
-rw-r--r--src/irc/debug.lua64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/irc/debug.lua b/src/irc/debug.lua
new file mode 100644
index 0000000..2e03d74
--- /dev/null
+++ b/src/irc/debug.lua
@@ -0,0 +1,64 @@
+-- initialization {{{
+local base = _G
+local io = require 'io'
+-- }}}
+
+module 'irc.debug'
+
+-- defaults {{{
+COLOR = true
+-- }}}
+
+-- local variables {{{
+local ON = false
+local outfile = io.output()
+-- }}}
+
+-- public functions {{{
+-- enable {{{
+function enable()
+ ON = true
+end
+-- }}}
+
+-- disable {{{
+function disable()
+ ON = false
+end
+-- }}}
+
+-- set_output {{{
+function set_output(file)
+ outfile = base.assert(io.open(file))
+end
+-- }}}
+
+-- message {{{
+function message(msg_type, msg, color)
+ if ON then
+ local endcolor = ""
+ if COLOR then
+ color = color or "\027[1;30m"
+ endcolor = "\027[0m"
+ else
+ color = ""
+ endcolor = ""
+ end
+ outfile:write(color .. msg_type .. ": " .. msg .. endcolor .. "\n")
+ end
+end
+-- }}}
+
+-- err {{{
+function err(msg)
+ message("ERR", msg, "\027[0;31m")
+ base.error(msg, 2)
+end
+-- }}}
+
+-- warn {{{
+function warn(msg)
+ message("WARN", msg, "\027[0;33m")
+end
+-- }}}
+-- }}}