Mercurial > wow > ouroloot
comparison LibFarmbuyer.lua @ 19:f560cf82e7d3
Smarter handling of missed item cache entries. Basic persistent logging of
debug messages (options panel or /loot debug alsolog) and script to print same.
| author | Farmbuyer of US-Kilrogg <farmbuyer@gmail.com> |
|---|---|
| date | Mon, 29 Aug 2011 01:29:13 +0000 |
| parents | 5ee4edd24c13 |
| children | 8f7ec6ccf5e3 |
comparison
equal
deleted
inserted
replaced
| 18:ca797c0f32d4 | 19:f560cf82e7d3 |
|---|---|
| 5 | 5 |
| 6 Library contents: | 6 Library contents: |
| 7 - author_debug | 7 - author_debug |
| 8 Evaluates to true if I'm hacking on something. | 8 Evaluates to true if I'm hacking on something. |
| 9 | 9 |
| 10 - tableprint(t) | 10 - tableprint(t[,f]) |
| 11 A single print() call to the contents of T, including nils; strings are | 11 A single print() call to the contents of T, including nils; strings are |
| 12 cleaned up with respect to embedded '|'/control chars. If there is a | 12 cleaned up with respect to embedded '|'/control chars. If a function F is |
| 13 global LIBFARMPRINT function, it is called with the cleaned-up T instead | 13 passed, calls that instead of print(). Returns the results of F, or the |
| 14 of directly calling print. | 14 text string passed to print(), depending on which was used. |
| 15 | 15 |
| 16 - safeprint(...) | 16 - safeprint(...) |
| 17 Same as tableprint() on the argument list. | 17 Same as tableprint() on the argument list. Returns the results of tableprint. |
| 18 | 18 |
| 19 - safeiprint(...) | 19 - safeiprint(...) |
| 20 Same as safeprint() but with index numbers inserted. Ex: | 20 Same as safeprint() but with <index> numbers inserted. Returns the results |
| 21 safeiprint(a,b,c) --> <1>,a,<2>,b,<3>,c | 21 of tableprint. |
| 22 | 22 Ex: safeiprint(a,b,c) --> <1>,a,<2>,b,<3>,c |
| 23 - CHAT(n) | |
| 24 Returns a function suitable for assigning to LIBFARMPRINT, directing all | |
| 25 output to builtin chat frame N. | |
| 26 | 23 |
| 27 - t = StaticPopup(t) | 24 - t = StaticPopup(t) |
| 28 Fills out "typical" settings inside T, especially if T contains any kind | 25 Fills out "typical" settings inside T, especially if T contains any kind |
| 29 of editbox: | 26 of editbox: |
| 30 + cannot accept an empty editbox | 27 + cannot accept an empty editbox |
| 51 | 48 |
| 52 - new(...), del(t), copy(t), clear() | 49 - new(...), del(t), copy(t), clear() |
| 53 Ditto for table recycling. | 50 Ditto for table recycling. |
| 54 ]] | 51 ]] |
| 55 | 52 |
| 56 local MAJOR, MINOR = "LibFarmbuyer", 11 | 53 local MAJOR, MINOR = "LibFarmbuyer", 12 |
| 57 assert(LibStub,MAJOR.." requires LibStub") | 54 assert(LibStub,MAJOR.." requires LibStub") |
| 58 local lib = LibStub:NewLibrary(MAJOR, MINOR) | 55 local lib = LibStub:NewLibrary(MAJOR, MINOR) |
| 59 if not lib then return end | 56 if not lib then return end |
| 60 | 57 |
| 61 _G[MAJOR] = lib | 58 _G[MAJOR] = lib |
| 99 | 96 |
| 100 ---------------------------------------------------------------------- | 97 ---------------------------------------------------------------------- |
| 101 --[[ | 98 --[[ |
| 102 safeprint | 99 safeprint |
| 103 ]] | 100 ]] |
| 101 local tconcat = table.concat | |
| 104 local function undocontrol(c) | 102 local function undocontrol(c) |
| 105 return ("\\%.3d"):format(c:byte()) | 103 return ("\\%.3d"):format(c:byte()) |
| 106 end | 104 end |
| 107 function lib.CHAT(n) | |
| 108 local cf = _G["ChatFrame"..n] | |
| 109 return function(t) | |
| 110 local msg = table.concat(t,' ', i, tonumber(t.n) or #t) | |
| 111 cf:AddMessage(msg) | |
| 112 end | |
| 113 end | |
| 114 function lib.safeprint(...) | 105 function lib.safeprint(...) |
| 115 local args = { n=select('#',...), ... } | 106 local args = { n=select('#',...), ... } |
| 116 lib.tableprint(args) | 107 return lib.tableprint(args) |
| 117 end | 108 end |
| 118 function lib.safeiprint(...) | 109 function lib.safeiprint(...) |
| 119 local args = { n=select('#',...), ... } | 110 local args = { n=select('#',...), ... } |
| 120 local last = args.n | 111 local last = args.n |
| 121 while last > 0 do | 112 while last > 0 do |
| 122 table.insert (args, last, "<"..last..">") | 113 table.insert (args, last, "<"..last..">") |
| 123 last = last - 1 | 114 last = last - 1 |
| 124 end | 115 end |
| 125 args.n = 2 * args.n | 116 args.n = 2 * args.n |
| 126 lib.tableprint(args) | 117 return lib.tableprint(args) |
| 127 end | 118 end |
| 128 function lib.tableprint(t) | 119 function lib.tableprint(t,f) |
| 129 for i = 1, (tonumber(t.n) or #t) do | 120 for i = 1, (tonumber(t.n) or #t) do |
| 130 t[i] = tostring(t[i]):gsub('\124','\124\124') | 121 t[i] = tostring(t[i]):gsub('\124','\124\124') |
| 131 :gsub('(%c)', undocontrol) | 122 :gsub('(%c)', undocontrol) |
| 132 end | 123 end |
| 133 if type(_G.LIBFARMPRINT) == 'function' then | 124 local msg = tconcat(t,' ', i, tonumber(t.n) or #t) |
| 134 return _G.LIBFARMPRINT(t) | 125 if f then |
| 126 return f(msg) | |
| 135 else | 127 else |
| 136 return print(unpack(t)) | 128 print(msg) |
| 129 return msg,t | |
| 137 end | 130 end |
| 138 end | 131 end |
| 139 | 132 |
| 140 -- See below for global versions. | 133 -- See below for global versions. |
| 141 | 134 |
| 293 ]]):gsub('\t',' ') | 286 ]]):gsub('\t',' ') |
| 294 | 287 |
| 295 local function CreateDispatcher(argCount) | 288 local function CreateDispatcher(argCount) |
| 296 local ARGS = {} | 289 local ARGS = {} |
| 297 for i = 1, argCount do ARGS[i] = "arg"..i end | 290 for i = 1, argCount do ARGS[i] = "arg"..i end |
| 298 local code = template:gsub("ARGS", table.concat(ARGS, ", ")) | 291 local code = template:gsub("ARGS", tconcat(ARGS, ", ")) |
| 299 return assert(loadstring(code, "LibF/safecall Dispatcher["..argCount.."]"))(xpcall, errorhandler) | 292 return assert(loadstring(code, "LibF/safecall Dispatcher["..argCount.."]"))(xpcall, errorhandler) |
| 300 end | 293 end |
| 301 | 294 |
| 302 local Dispatchers = setmetatable({ | 295 local Dispatchers = setmetatable({ |
| 303 [0] = function(func) | 296 [0] = function(func) |
