comparison libs/AceDebug-2.0/AceDebug-2.0.lua @ 1:c11ca1d8ed91

Version 0.1
author Flick <flickerstreak@gmail.com>
date Tue, 20 Mar 2007 21:03:57 +0000
parents
children
comparison
equal deleted inserted replaced
0:4e2ce2894c21 1:c11ca1d8ed91
1 --[[
2 Name: AceDebug-2.0
3 Revision: $Rev: 18708 $
4 Developed by: The Ace Development Team (http://www.wowace.com/index.php/The_Ace_Development_Team)
5 Inspired By: Ace 1.x by Turan (turan@gryphon.com)
6 Website: http://www.wowace.com/
7 Documentation: http://www.wowace.com/index.php/AceDebug-2.0
8 SVN: http://svn.wowace.com/root/trunk/Ace2/AceDebug-2.0
9 Description: Mixin to allow for simple debugging capabilities.
10 Dependencies: AceLibrary, AceOO-2.0
11 ]]
12
13 local MAJOR_VERSION = "AceDebug-2.0"
14 local MINOR_VERSION = "$Revision: 18708 $"
15
16 if not AceLibrary then error(MAJOR_VERSION .. " requires AceLibrary") end
17 if not AceLibrary:IsNewVersion(MAJOR_VERSION, MINOR_VERSION) then return end
18
19 if not AceLibrary:HasInstance("AceOO-2.0") then error(MAJOR_VERSION .. " requires AceOO-2.0") end
20
21 if GetLocale() == "frFR" then
22 DEBUGGING = "D\195\169boguage"
23 TOGGLE_DEBUGGING = "Activer/d\195\169sactiver le d\195\169boguage"
24 elseif GetLocale() == "deDE" then
25 DEBUGGING = "Debuggen"
26 TOGGLE_DEBUGGING = "Aktiviert/Deaktiviert Debugging"
27 elseif GetLocale() == "koKR" then
28 DEBUGGING = "디버깅"
29 TOGGLE_DEBUGGING = "디버깅 기능 사용함/사용안함"
30 elseif GetLocale() == "zhTW" then
31 DEBUGGING = "除錯"
32 TOGGLE_DEBUGGING = "啟用/停用除錯功能"
33 elseif GetLocale() == "zhCN" then
34 DEBUGGING = "\232\176\131\232\175\149"
35 TOGGLE_DEBUGGING = "\229\144\175\231\148\168/\231\166\129\231\148\168 \232\176\131\232\175\149"
36 else -- enUS
37 DEBUGGING = "Debugging"
38 TOGGLE_DEBUGGING = "Enable/disable debugging"
39 end
40
41 local AceOO = AceLibrary:GetInstance("AceOO-2.0")
42 local AceDebug = AceOO.Mixin {"Debug", "CustomDebug", "IsDebugging", "SetDebugging", "SetDebugLevel", "LevelDebug", "CustomLevelDebug", "GetDebugLevel"}
43
44 local function print(text, r, g, b, frame, delay)
45 (frame or DEFAULT_CHAT_FRAME):AddMessage(text, r, g, b, 1, delay or 5)
46 end
47
48 local tmp = {}
49
50 function AceDebug:CustomDebug(r, g, b, frame, delay, a1, ...)
51 if not self.debugging then
52 return
53 end
54
55 local output = string.format("|cff7fff7f(DEBUG) %s:[%s.%3d]|r", tostring(self), date("%H:%M:%S"), math.fmod(GetTime(), 1) * 1000)
56
57 a1 = tostring(a1)
58 if string.find(a1, "%%") and select('#', ...) >= 1 then
59 for i = 1, select('#', ...) do
60 tmp[i] = tostring((select(i, ...)))
61 end
62 output = output .. " " .. string.format(a1, unpack(tmp))
63 for i = 1, select('#', ...) do
64 tmp[i] = nil
65 end
66 else
67 -- This block dynamically rebuilds the tmp array stopping on the first nil.
68 tmp[1] = output
69 tmp[2] = a1
70 for i = 1, select('#', ...) do
71 tmp[i+2] = tostring((select(i, ...)))
72 end
73
74 output = table.concat(tmp, " ")
75
76 for i = 1, select('#', ...) + 2 do
77 tmp[i] = nil
78 end
79 end
80
81 print(output, r, g, b, frame or self.debugFrame, delay)
82 end
83
84 function AceDebug:Debug(...)
85 AceDebug.CustomDebug(self, nil, nil, nil, nil, nil, ...)
86 end
87
88 function AceDebug:IsDebugging()
89 return self.debugging
90 end
91
92 function AceDebug:SetDebugging(debugging)
93 self.debugging = debugging
94 end
95
96 -- Takes a number 1-3
97 -- Level 1: Critical messages that every user should receive
98 -- Level 2: Should be used for local debugging (function calls, etc)
99 -- Level 3: Very verbose debugging, will dump everything and anything
100 -- If set to nil, you will receive no debug information
101 function AceDebug:SetDebugLevel(level)
102 AceDebug:argCheck(level, 1, "number", "nil")
103 if not level then
104 self.debuglevel = nil
105 return
106 end
107 if level < 1 or level > 3 then
108 AceDebug:error("Bad argument #1 to `SetDebugLevel`, must be a number 1-3")
109 end
110 self.debuglevel = level
111 end
112
113 function AceDebug:GetDebugLevel()
114 return self.debuglevel
115 end
116
117 function AceDebug:CustomLevelDebug(level, r, g, b, frame, delay, ...)
118 if not self.debugging or not self.debuglevel then return end
119 AceDebug:argCheck(level, 1, "number")
120 if level < 1 or level > 3 then
121 AceDebug:error("Bad argument #1 to `LevelDebug`, must be a number 1-3")
122 end
123 if level > self.debuglevel then return end
124
125 local output = string.format("|cff7fff7f(DEBUG) %s:[%s.%3d]|r", tostring(self), date("%H:%M:%S"), math.fmod(GetTime(), 1) * 1000)
126
127 a1 = tostring(a1)
128 if string.find(a1, "%%") and select('#', ...) >= 2 then
129 for i = 1, select('#', ...) do
130 tmp[i] = tostring((select(i, ...)))
131 end
132 output = output .. " " .. string.format(a1, unpack(tmp))
133 for i = 1, select('#', ...) do
134 tmp[i] = nil
135 end
136 else
137 -- This block dynamically rebuilds the tmp array stopping on the first nil.
138 tmp[1] = output
139 tmp[2] = a1
140 for i = 1, select('#', ...) do
141 tmp[i+2] = tostring((select(i, ...)))
142 end
143
144 output = table.concat(tmp, " ")
145
146 for i = 1, select('#', ...) + 2 do
147 tmp[i] = nil
148 end
149 end
150
151 print(output, r, g, b, frame or self.debugFrame, delay)
152 end
153
154 function AceDebug:LevelDebug(level, ...)
155 if not self.debugging or not self.debuglevel then return end
156 AceDebug:argCheck(level, 1, "number")
157 if level < 1 or level > 3 then
158 AceDebug:error("Bad argument #1 to `LevelDebug`, must be a number 1-3")
159 end
160 if level > self.debuglevel then return end
161
162 AceDebug.CustomLevelDebug(self, level, nil, nil, nil, nil, nil, ...)
163 end
164
165
166 local options
167 function AceDebug:GetAceOptionsDataTable(target)
168 if not options then
169 options = {
170 debug = {
171 name = DEBUGGING,
172 desc = TOGGLE_DEBUGGING,
173 type = "toggle",
174 get = "IsDebugging",
175 set = "SetDebugging",
176 order = -2,
177 }
178 }
179 end
180 return options
181 end
182
183 AceLibrary:Register(AceDebug, MAJOR_VERSION, MINOR_VERSION, AceDebug.activate)
184 AceDebug = AceLibrary(MAJOR_VERSION)