diff LibFarmbuyer.lua @ 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 8f7ec6ccf5e3
children 7af58a7dce7d
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