Skip to content

Commit c45eeb6

Browse files
authored
Merge pull request kmarkus#7 from meyerj/added-print-fcn-argument-to-gen_dbgcolor
Added optional print_fcn argument to rfsmpp.gen_dbgcolor
2 parents 576d513 + a417a9c commit c45eeb6

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

rfsmpp.lua

+15-8
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,7 @@ local ctab = {
7777
TIMEEVENT = ac.yellow .. ac.bright
7878
}
7979

80-
--- Colorized fsm.dbg hook replacement.
81-
function dbgcolor(name, ...)
80+
function dbgcolorize(name, ...)
8281
local str = ""
8382
local args = { ... }
8483

@@ -93,21 +92,29 @@ function dbgcolor(name, ...)
9392
else
9493
str = str .. utils.rpad(ptab[1], pad) .. table.concat(ptab, ' ', 2)
9594
end
96-
print(str)
95+
96+
return str
97+
end
98+
99+
--- Colorized fsm.dbg hook replacement.
100+
function dbgcolor(name, ...)
101+
print(dbgcolorize(name, ...))
97102
end
98103

99104
--- Generate a configurable dbgcolor function.
100105
-- @param name string name to prepend to printed message.
101106
-- @param ftab table of the dbg ids to print.
102107
-- @param defshow if false fields not mentioned in ftab are not shown. If true they are.
103-
function gen_dbgcolor(name, ftab, defshow)
108+
-- @param print_fcn a function actually used for printing. Defaults to print.
109+
function gen_dbgcolor(name, ftab, defshow, print_fcn)
104110
name = name or "<unnamed SM>"
105111
ftab = ftab or {}
106112
if defshow == nil then defshow = true end
113+
if print_fcn == nil then print_fcn = print end
107114

108115
return function (tag, ...)
109-
if ftab[tag] == true then dbgcolor(name, tag, ...)
110-
elseif ftab[tag] == false then return
111-
else if defshow then dbgcolor(name, tag, ...) end end
112-
end
116+
if ftab[tag] == true then print_fcn(dbgcolorize(name, tag, ...))
117+
elseif ftab[tag] == false then return
118+
else if defshow then print_fcn(dbgcolorize(name, tag, ...)) end end
119+
end
113120
end

0 commit comments

Comments
 (0)