5 local io = require 'io'
9 -- This module implements a few useful debug functions for use throughout the
17 -- local variables {{{
19 local outfile = io.output()
22 -- internal functions {{{
25 -- Output a debug message.
26 -- @param msg_type Arbitrary string corresponding to the type of message
27 -- @param msg Message text
28 -- @param color Which terminal code to use for color output (defaults to
30 function _message(msg_type, msg, color)
33 if COLOR and outfile == io.stdout then
34 color = color or "\027[1;30m"
40 outfile:write(color .. msg_type .. ": " .. msg .. endcolor .. "\n")
47 -- Signal an error. Writes the error message to the screen in red and calls
49 -- @param msg Error message
52 _message("ERR", msg, "\027[0;31m")
59 -- Signal a warning. Writes the warning message to the screen in yellow.
60 -- @param msg Warning message
62 _message("WARN", msg, "\027[0;33m")
67 -- public functions {{{
70 -- Turns on debug output.
78 -- Turns off debug output.
86 -- Redirects output to a file rather than stdout.
87 -- @param file File to write debug output to
88 function set_output(file)
89 outfile = base.assert(io.open(file))