diff 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
line wrap: on
line diff
--- a/LibFarmbuyer.lua	Fri Aug 26 02:52:33 2011 +0000
+++ b/LibFarmbuyer.lua	Mon Aug 29 01:29:13 2011 +0000
@@ -7,22 +7,19 @@
 - author_debug
   Evaluates to true if I'm hacking on something.
 
-- tableprint(t)
+- 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 there is a
-  global LIBFARMPRINT function, it is called with the cleaned-up T instead
-  of directly calling print.
+  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.
 
 - safeprint(...)
-  Same as tableprint() on the argument list.
+  Same as tableprint() on the argument list.  Returns the results of tableprint.
 
 - safeiprint(...)
-  Same as safeprint() but with index numbers inserted.  Ex:
-  safeiprint(a,b,c)  -->  <1>,a,<2>,b,<3>,c
-
-- CHAT(n)
-  Returns a function suitable for assigning to LIBFARMPRINT, directing all
-  output to builtin chat frame N.
+  Same as safeprint() but with <index> numbers inserted.  Returns the results
+  of tableprint.
+  Ex:  safeiprint(a,b,c)  -->  <1>,a,<2>,b,<3>,c
 
 - t = StaticPopup(t)
   Fills out "typical" settings inside T, especially if T contains any kind
@@ -53,7 +50,7 @@
   Ditto for table recycling.
 ]]
 
-local MAJOR, MINOR = "LibFarmbuyer", 11
+local MAJOR, MINOR = "LibFarmbuyer", 12
 assert(LibStub,MAJOR.." requires LibStub")
 local lib = LibStub:NewLibrary(MAJOR, MINOR)
 if not lib then return end
@@ -101,19 +98,13 @@
 --[[
 	safeprint
 ]]
+local tconcat = table.concat
 local function undocontrol(c)
 	return ("\\%.3d"):format(c:byte())
 end
-function lib.CHAT(n)
-	local cf = _G["ChatFrame"..n]
-	return function(t)
-		local msg = table.concat(t,' ', i, tonumber(t.n) or #t)
-		cf:AddMessage(msg)
-	end
-end
 function lib.safeprint(...)
 	local args = { n=select('#',...), ... }
-	lib.tableprint(args)
+	return lib.tableprint(args)
 end
 function lib.safeiprint(...)
 	local args = { n=select('#',...), ... }
@@ -123,17 +114,19 @@
 		last = last - 1
 	end
 	args.n = 2 * args.n
-	lib.tableprint(args)
+	return lib.tableprint(args)
 end
-function lib.tableprint(t)
+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
-	if type(_G.LIBFARMPRINT) == 'function' then
-		return _G.LIBFARMPRINT(t)
+	local msg = tconcat(t,' ', i, tonumber(t.n) or #t)
+	if f then
+		return f(msg)
 	else
-		return print(unpack(t))
+		print(msg)
+		return msg,t
 	end
 end
 
@@ -295,7 +288,7 @@
 	local function CreateDispatcher(argCount)
 		local ARGS = {}
 		for i = 1, argCount do ARGS[i] = "arg"..i end
-		local code = template:gsub("ARGS", table.concat(ARGS, ", "))
+		local code = template:gsub("ARGS", tconcat(ARGS, ", "))
 		return assert(loadstring(code, "LibF/safecall Dispatcher["..argCount.."]"))(xpcall, errorhandler)
 	end