Mercurial > wow > ouroloot
changeset 45:1001dd95dbeb
If tekDebug is found, feed debugging messages there instead of print(); 'alsolog' functionality unchanged.
author | Farmbuyer of US-Kilrogg <farmbuyer@gmail.com> |
---|---|
date | Fri, 20 Jan 2012 11:48:38 +0000 |
parents | a561a967b5e6 |
children | 0b1e703a6954 |
files | LibFarmbuyer.lua Ouro_Loot.toc core.lua |
diffstat | 3 files changed, 55 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/LibFarmbuyer.lua Fri Jan 20 10:46:58 2012 +0000 +++ b/LibFarmbuyer.lua Fri Jan 20 11:48:38 2012 +0000 @@ -10,17 +10,21 @@ - tableprint(t[,f]) A single print() call to the contents of T, including nils; strings are cleaned up with respect to embedded '|'/control chars. If a function F is - passed, calls that instead of print(). Returns the results of F, or the - text string passed to print(), depending on which was used. + passed, calls that instead of print(). Returns the accumulated string and + either T or the returned values of F, depending on which was used. - safeprint(...) Same as tableprint() on the argument list. Returns the results of tableprint. + Generates some garbage. - safeiprint(...) Same as safeprint() but with <index> numbers inserted. Returns the results - of tableprint. + of tableprint. Generates some garbage. Ex: safeiprint(a,b,c) --> <1>,a,<2>,b,<3>,c +- safefprint/safefiprint(f,...) + Takes a function F as first parameter, for passing to tableprint(). + - t = StaticPopup(t) Fills out "typical" settings inside T, especially if T contains any kind of editbox: @@ -50,7 +54,7 @@ Ditto for table recycling. ]] -local MAJOR, MINOR = "LibFarmbuyer", 13 +local MAJOR, MINOR = "LibFarmbuyer", 14 assert(LibStub,MAJOR.." requires LibStub") local lib = LibStub:NewLibrary(MAJOR, MINOR) if not lib then return end @@ -106,6 +110,10 @@ local args = { n=select('#',...), ... } return lib.tableprint(args) end +function lib.safefprint(f,...) + local args = { n=select('#',...), ... } + return lib.tableprint(args,f) +end function lib.safeiprint(...) local args = { n=select('#',...), ... } local last = args.n @@ -116,14 +124,24 @@ args.n = 2 * args.n return lib.tableprint(args) end +function lib.safefiprint(f,...) + local args = { n=select('#',...), ... } + local last = args.n + while last > 0 do + table.insert (args, last, "<"..last..">") + last = last - 1 + end + args.n = 2 * args.n + return lib.tableprint(args,f) +end function lib.tableprint(t,f) for i = 1, (tonumber(t.n) or #t) do t[i] = tostring(t[i]):gsub('\124','\124\124') :gsub('(%c)', undocontrol) end local msg = tconcat(t,' ', i, tonumber(t.n) or #t) - if f then - return f(msg) + if type(f) == 'function' then + return msg,f(msg) else print(msg) return msg,t
--- a/Ouro_Loot.toc Fri Jan 20 10:46:58 2012 +0000 +++ b/Ouro_Loot.toc Fri Jan 20 11:48:38 2012 +0000 @@ -4,7 +4,7 @@ ## Notes: Raid loot tracking and text generation ## Author: Farmbuyer of US-Kilrogg ## SavedVariables: OuroLootSV, OuroLootSV_saved, OuroLootSV_opts, OuroLootSV_hist, OuroLootSV_log -## OptionalDeps: Ace3, DBM-Core, lib-st, LibFarmbuyer +## OptionalDeps: Ace3, DBM-Core, lib-st, LibFarmbuyer, tekDebug #@no-lib-strip@ libs\LibStub\LibStub.lua
--- a/core.lua Fri Jan 20 10:46:58 2012 +0000 +++ b/core.lua Fri Jan 20 11:48:38 2012 +0000 @@ -104,6 +104,15 @@ identTg = "OuroLoot2Tg" status_text = nil + tekdebug = nil + if _G.tekDebug then + local tdframe = _G.tekDebug:GetFrame("Ouro Loot") + function tekdebug (txt) + -- tekDebug notices "<name passed to getframe>|r:" + tdframe:AddMessage('|cff17ff0dOuro Loot|r:'..txt,1,1,1) + end + end + DEBUG_PRINT = false debug = { comm = false, @@ -113,18 +122,31 @@ cache = false, alsolog = false, } - function dprint (t,...) - if DEBUG_PRINT and debug[t] then - local text = flib.safeprint("<"..t.."> ",...) - if debug.alsolog then - addon:log_with_timestamp(text) + -- This looks ugly, but it factors out the load-time decisions from + -- the run-time ones. + if tekdebug then + function dprint (t,...) + if DEBUG_PRINT and debug[t] then + local text = flib.safefprint(tekdebug,"<"..t.."> ",...) + if debug.alsolog then + addon:log_with_timestamp(text) + end + end + end + else + function dprint (t,...) + if DEBUG_PRINT and debug[t] then + local text = flib.safeprint("<"..t.."> ",...) + if debug.alsolog then + addon:log_with_timestamp(text) + end end end end - if author_debug then - function pprint(t,...) - local text = flib.safeprint("<<"..t..">> ",...) + if author_debug and tekdebug then + function pprint (t,...) + local text = flib.safefprint(tekdebug,"<<"..t..">> ",...) if debug.alsolog then addon:log_with_timestamp(text) end