vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 --
3 -- Sea.IO
4 --
5 -- Common Input/Output Functions for WoW
6 --
7 -- $LastChangedBy: karlkfi $
8 -- $Rev: 3616 $
9 -- $Date: 2006-05-30 12:45:23 -0500 (Tue, 30 May 2006) $
10 --]]
11  
12 --Compatible with the following Mini-Libs
13 Sea.versions.SeaString = 0.12;
14  
15 -- Globals
16 SEA_DEBUG = false;
17 SEA_ERROR = false;
18  
19 Sea.IO = {
20 -- Default chat frame set to ChatFrame1
21 DEFAULT_PRINT_FRAME = ChatFrame1;
22  
23 -- Default error frame set to ChatFrame1
24 DEFAULT_ERROR_FRAME = ChatFrame1;
25  
26 -- Default banner frame
27 DEFAULT_BANNER_FRAME = UIErrorsFrame;
28  
29 -- Default color scheme
30 DEFAULT_ERROR_COLOR = RED_FONT_COLOR;
31 DEFAULT_PRINT_COLOR = NORMAL_FONT_COLOR;
32  
33 -- Default Debug Tag
34 debugKey = "SEA_DEBUG";
35  
36 -- Default Error Tag
37 errorKey = "SEA_ERROR";
38  
39 -- Recursive check
40 recursed = false;
41  
42 --[[ Standard Prints ]]--
43  
44 --
45 -- print ( ... )
46 --
47 -- Arguments
48 -- () arg
49 -- arg - the values to be printed
50 --
51 -- Returns
52 -- (nil)
53 --
54 print = function(...)
55 Sea.IO.printf(nil, unpack(arg));
56 end;
57  
58 --
59 -- banner ( ... )
60 --
61 -- Arguments
62 -- () arg
63 -- arg - the values to be printed
64 --
65 -- Returns
66 -- (nil)
67 --
68 banner = function(...)
69 Sea.IO.printf(Sea.IO.DEFAULT_BANNER_FRAME, unpack(arg));
70 end;
71  
72 --
73 -- error (...)
74 --
75 -- prints just like Sea.IO.print, except as an error
76 --
77 -- Arguments:
78 -- () arg
79 -- arg - contains all error output
80 --
81 error = function(...)
82 Sea.IO.errorfc(nil, nil, unpack(arg) );
83 end;
84  
85 --
86 -- dprint (string debugkey, ...)
87 --
88 -- prints a message when getglobal(debugkey) is true
89 --
90 -- Arguments:
91 -- (string debugkey) arg
92 --
93 dprint = function ( debugKey, ... )
94 Sea.IO.dprintf(debugKey, Sea.IO.DEFAULT_PRINT_FRAME, unpack(arg));
95 end;
96  
97  
98 --
99 -- dprintc (string debugkey, Table[r,g,b] color, ...)
100 --
101 -- prints a message when getglobal(debugkey) is true
102 -- in the color specified by color
103 --
104 -- Arguments:
105 -- (string debugkey, Table[r,g,b] color) arg
106 --
107 dprintc = function ( debugKey, color, ... )
108 Sea.IO.dprintfc(debugKey, Sea.IO.DEFAULT_PRINT_FRAME, color, unpack(arg));
109 end;
110  
111 --
112 -- derror (string errorKey, ...)
113 --
114 -- prints an error when getglobal(errorKey) is true
115 --
116 -- Arguments:
117 -- (string errorKey) arg
118 --
119 derror = function ( errorKey, ... )
120 Sea.IO.derrorf(errorKey, Sea.IO.DEFAULT_ERROR_FRAME, unpack(arg));
121 end;
122  
123 --
124 -- derrorf (string errorKey, MessageFrame frame, ...)
125 --
126 -- prints an error when getglobal(errorKey) is true
127 --
128 -- Arguments:
129 -- (string errorKey, MessageFrame frame) arg
130 --
131 derrorf = function ( errorKey, frame, ... )
132 Sea.IO.derrorfc(errorKey, frame, Sea.IO.DEFAULT_ERROR_COLOR, unpack(arg));
133 end;
134  
135 --
136 -- derrorc (string errorKey, Table[r,g,b] color, ...)
137 --
138 -- prints an error when getglobal(errorKey) is true
139 -- in the color specified by color
140 --
141 -- Arguments:
142 -- (string errorKey, Table[r,g,b] color) arg
143 --
144 derrorc = function ( errorKey, color, ... )
145 Sea.IO.derrorfc(errorKey, Sea.IO.DEFAULT_ERROR_FRAME, color, unpack(arg));
146 end;
147  
148 --
149 -- derrorfc (string errorKey, MessageFrame frame, Table[r,g,b] color, ...)
150 --
151 -- prints an error when getglobal(errorKey) is true
152 -- in the frame specified, in the color specified
153 --
154 -- Arguments:
155 -- (string errorKey, MessageFrame frame, Table[r,g,b] color) arg
156 --
157 --
158 derrorfc = function ( errorKey, frame, color, ... )
159 if ( type(errorKey) ~= "string" ) then
160 if ( type(errorKey) == "nil" ) then
161 errorKey = Sea.IO.errorKey;
162 else
163 --Sea.IO.error("Invalid error key. Type: ", type(errorKey));
164 end
165 end
166 if ( getglobal(errorKey) == true ) then
167 Sea.IO.errorfc(frame, color, unpack(arg));
168 end
169 end;
170  
171  
172 --
173 -- dbanner (string debugkey, ...)
174 --
175 -- prints a banner when getglobal(debugkey) is true
176 --
177 -- Arguments:
178 -- (string debugkey) arg
179 --
180 dbanner = function ( debugKey, ... )
181 Sea.IO.dprintf(debugKey, Sea.IO.DEFAULT_BANNER_FRAME, unpack(arg));
182 end;
183  
184 --
185 -- dbannerc (string debugkey, Table[r,g,b] ...)
186 --
187 -- prints a banner when getglobal(debugkey) is true
188 -- in the color specified by color
189 --
190 -- Arguments:
191 -- (string debugkey, Table[r,g,b] color) arg
192 --
193 dbannerc = function ( debugKey, color, ... )
194 Sea.IO.dprintfc(debugKey, Sea.IO.DEFAULT_BANNER_FRAME, color, unpack(arg));
195 end;
196  
197 --
198 -- printf (MessageFrame frame, ...)
199 --
200 -- prints a message in a message frame
201 --
202 -- Arguments:
203 -- (MessageFrame frame) arg
204 --
205 -- frame - the object with AddMessage(self, string)
206 -- arg - the string to be composed
207 --
208 -- Returns
209 -- (nil)
210 --
211  
212 printf = function (frame, ... )
213 Sea.IO.printfc(frame, nil, unpack(arg));
214 end;
215  
216 --
217 -- dprintf (string debugkey, MessageFrame frame, ...)
218 --
219 -- prints a message when getglobal(debugkey) is true
220 -- also decodes | and characters
221 --
222 -- Arguments:
223 -- (string debugkey, MessageFrame frame) arg
224 -- debugkey - string debug key
225 -- frame - debug target frame
226 --
227 dprintf = function ( debugKey, frame, ... )
228 Sea.IO.dprintfc(debugKey, frame, nil, unpack(arg));
229 end;
230  
231  
232 --
233 -- dprintfc (string debugkey, MessageFrame frame, Table[r,g,b] color, ...)
234 --
235 -- prints a message when getglobal(debugkey) is true
236 -- also decodes | and characters, using the specified color
237 --
238 -- Arguments:
239 -- (string debugkey, MessageFrame frame) arg
240 -- debugkey - string/boolean debug key
241 -- if nil, then "getglobal(Sea.IO.debugKey)" is used;
242 -- if string, then "getglobal(debugKey)" is used;
243 -- if boolean or non-string it is evaluated to print using "if (debugKey) then";
244 -- frame - debug target frame
245 -- color - table of colors
246 --
247 dprintfc = function ( debugKey, frame, color, ... )
248 if ( type(debugKey) == "string" ) then
249 debugKey = getglobal(debugKey);
250 elseif ( debugKey == nil ) then
251 debugKey = getglobal(Sea.IO.debugKey);
252 end
253  
254 local msg = Sea.util.join(arg,"");
255 msg = string.gsub(msg,"|","<pipe>");
256 msg = string.gsub(msg,"([^%w%s%a%p])",Sea.string.byte);
257  
258 if ( debugKey ) then
259 Sea.IO.printfc(frame, color, unpack(arg));
260  
261 if IsAddOnLoaded( "!ImprovedErrorFrame" ) then
262 ImprovedErrorFrame.newErrorMessage(Sea.util.join(arg, ""), this:GetName())
263 end
264 end
265 end;
266  
267  
268  
269 --
270 -- errorc (Table[r,g,b] color, ...)
271 --
272 -- prints just like Sea.IO.print, except as an error with the color
273 --
274 -- Arguments:
275 -- (Table[r,g,b] color) arg
276 -- color - the specified color
277 -- arg - contains all error output
278 --
279 errorc = function(color, ...)
280 Sea.IO.errorfc(Sea.IO.DEFAULT_ERROR_FRAME, color, unpack(arg) );
281 end;
282  
283 --
284 -- errorf (MessageFrame frame, ...)
285 --
286 -- prints a message in an error message frame
287 --
288 -- Arguments:
289 -- (MessageFrame frame) arg
290 --
291 -- frame - the object with AddMessage(self, string)
292 -- arg - the string to be composed
293 --
294 -- Returns
295 -- (nil)
296 --
297  
298 errorf = function (frame, ... )
299 Sea.IO.errorfc(frame, nil, unpack(arg));
300 end;
301  
302 --
303 -- errorfc (MessageFrame frame, Table[r,g,b] color, ...)
304 --
305 -- prints a message in an error message frame with the color
306 --
307 -- Arguments:
308 -- (MessageFrame frame, Table[r,g,b] color) arg
309 --
310 -- frame - the object with AddMessage(self, string)
311 -- color - table containing the colors
312 -- arg - the string to be composed
313 --
314 -- Returns
315 -- (nil)
316 --
317  
318 errorfc = function (frame, color, ... )
319 if ( frame == nil ) then
320 frame = Sea.IO.DEFAULT_ERROR_FRAME;
321 end
322 if ( color == nil ) then
323 color = Sea.IO.DEFAULT_ERROR_COLOR;
324 end
325  
326 Sea.IO.printfc(frame, color, unpack(arg));
327 end;
328 --
329 -- printc ( ColorTable[r,g,b] color, ... )
330 --
331 -- prints a message in the default frame with a
332 -- specified color
333 --
334 -- Arguments:
335 -- color - the color
336 -- arg - the message
337 --
338 printc = function ( color, ... )
339 Sea.IO.printfc(nil, color, unpack(arg));
340 end;
341  
342 --
343 -- bannerc ( ColorTable[r,g,b] color, ... )
344 --
345 -- prints a banner message with a
346 -- specified color
347 --
348 -- Arguments:
349 -- color - the color
350 -- arg - the message
351 --
352 bannerc = function ( color, ... )
353 if ( color == nil ) then
354 color = Sea.IO.DEFAULT_PRINT_COLOR;
355 end
356  
357 Sea.IO.printfc(Sea.IO.DEFAULT_BANNER_FRAME, color, unpack(arg));
358 end;
359  
360 --
361 -- printfc (MessageFrame frame, ColorTable[r,g,b] color, ... )
362 --
363 -- prints a message in a frame with a specified color
364 --
365 -- Arguments
366 -- frame - the frame
367 -- color - a table with .r .g and .b values
368 -- arg - the message objects
369 --
370 printfc = function (frame, color, ... )
371 if ( frame == nil ) then
372 frame = Sea.IO.DEFAULT_PRINT_FRAME;
373 end
374 if ( color == nil ) then
375 color = Sea.IO.DEFAULT_PRINT_COLOR;
376 end
377  
378 if ( Sea.IO.recursed == false ) then
379 Sea.IO.recursed = true;
380 if ( frame == Sea.IO.DEFAULT_BANNER_FRAME ) then
381 frame:AddMessage(Sea.util.join(arg,""), color.r, color.g, color.b, 1.0, UIERRORS_HOLD_TIME);
382 else
383 frame:AddMessage(Sea.util.join(arg,""), color.r, color.g, color.b);
384 end
385 Sea.IO.recursed = false;
386 else
387 if ( frame == Sea.IO.DEFAULT_BANNER_FRAME ) then
388 frame:AddMessage(arg[1], color.r, color.g, color.b, 1.0, UIERRORS_HOLD_TIME);
389 else
390 frame:AddMessage(arg[1], color.r, color.g, color.b);
391 end
392 end
393 end;
394  
395 --[[ End of Standard Prints ]]--
396  
397 --[[ Beginning of Special Prints ]]--
398  
399 --
400 -- printComma (...)
401 --
402 -- Prints the arguments separated by commas
403 --
404 printComma = function(...)
405 Sea.IO.print(Sea.util.join(arg,","));
406 end;
407  
408 --
409 -- printTable (table, [rowname, level])
410 --
411 -- Recursively prints a table
412 --
413 -- Args:
414 -- table - table to be printed
415 -- rowname - row's name
416 -- level - level of depth
417 --
418 printTable = function (table, rowname, level)
419 if ( level == nil ) then level = 1; end
420  
421 if ( type(rowname) == "nil" ) then rowname = "ROOT";
422 elseif ( type(rowname) == "string" ) then
423 rowname = "\""..rowname.."\"";
424 elseif ( type(rowname) ~= "number" ) then
425 rowname = "*"..type(rowname).."*";
426 end
427  
428 local msg = "";
429 for i=1,level, 1 do
430 msg = msg .. " ";
431 end
432  
433 if ( table == nil ) then
434 Sea.IO.print(msg,"[",rowname,"] := nil "); return
435 end
436 if ( type(table) == "table" ) then
437 Sea.IO.print (msg,rowname," { ");
438 for k,v in table do
439 Sea.io.printTable(v,k,level+1);
440 end
441 Sea.IO.print(msg,"}");
442 elseif (type(table) == "function" ) then
443 Sea.IO.print(msg,"[",rowname,"] => {{FunctionPtr*}}");
444 elseif (type(table) == "userdata" ) then
445 Sea.IO.print(msg,"[",rowname,"] => {{UserData}}");
446 elseif (type(table) == "boolean" ) then
447 local value = "true";
448 if ( not table ) then
449 value = "false";
450 end
451 Sea.IO.print(msg,"[",rowname,"] => ",value);
452 else
453 Sea.IO.print(msg,"[",rowname,"] => ",table);
454 end
455 end
456 };
457  
458 -- Aliases:
459 Sea.io = Sea.IO;