vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --[[ |
2 | Name: AceDebug-2.0 |
||
3 | Revision: $Rev: 15024 $ |
||
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: 15024 $" |
||
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 | local DEBUGGING, TOGGLE_DEBUGGING |
||
22 | |||
23 | if GetLocale() == "frFR" then |
||
24 | DEBUGGING = "D\195\169boguage" |
||
25 | TOGGLE_DEBUGGING = "Activer/d\195\169sactiver le d\195\169boguage" |
||
26 | elseif GetLocale() == "deDE" then |
||
27 | DEBUGGING = "Debuggen" |
||
28 | TOGGLE_DEBUGGING = "Aktiviert/Deaktiviert Debugging" |
||
29 | elseif GetLocale() == "koKR" then |
||
30 | DEBUGGING = "디버깅" |
||
31 | TOGGLE_DEBUGGING = "디버깅 기능 사용함/사용안함" |
||
32 | elseif GetLocale() == "zhTW" then |
||
33 | DEBUGGING = "除錯" |
||
34 | TOGGLE_DEBUGGING = "啟用/停用除錯功能" |
||
35 | elseif GetLocale() == "zhCN" then |
||
36 | DEBUGGING = "\232\176\131\232\175\149" |
||
37 | TOGGLE_DEBUGGING = "\229\144\175\231\148\168/\231\166\129\231\148\168 \232\176\131\232\175\149" |
||
38 | else -- enUS |
||
39 | DEBUGGING = "Debugging" |
||
40 | TOGGLE_DEBUGGING = "Enable/disable debugging" |
||
41 | end |
||
42 | |||
43 | local table_setn |
||
44 | do |
||
45 | local version = GetBuildInfo() |
||
46 | if string.find(version, "^2%.") then |
||
47 | -- 2.0.0 |
||
48 | table_setn = function() end |
||
49 | else |
||
50 | table_setn = table.setn |
||
51 | end |
||
52 | end |
||
53 | |||
54 | local math_mod = math.mod or math.fmod |
||
55 | |||
56 | local AceOO = AceLibrary:GetInstance("AceOO-2.0") |
||
57 | local AceDebug = AceOO.Mixin {"Debug", "CustomDebug", "IsDebugging", "SetDebugging", "SetDebugLevel", "LevelDebug", "CustomLevelDebug", "GetDebugLevel"} |
||
58 | |||
59 | local function print(text, r, g, b, frame, delay) |
||
60 | (frame or DEFAULT_CHAT_FRAME):AddMessage(text, r, g, b, 1, delay or 5) |
||
61 | end |
||
62 | |||
63 | local tmp |
||
64 | |||
65 | function AceDebug:CustomDebug(r, g, b, frame, delay, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) |
||
66 | if not self.debugging then return end |
||
67 | |||
68 | local output = string.format("|cff7fff7f(DEBUG) %s:[%s%3d]|r", tostring(self), date("%H:%M:%S"), math_mod(GetTime(), 1) * 1000) |
||
69 | |||
70 | if string.find(tostring(a1), "%%") then |
||
71 | output = output .. " " .. string.format(tostring(a1), tostring(a2), tostring(a3), tostring(a4), tostring(a5), tostring(a6), tostring(a7), tostring(a8), tostring(a9), tostring(a10), tostring(a11), tostring(a12), tostring(a13), tostring(a14), tostring(a15), tostring(a16), tostring(a17), tostring(a18), tostring(a19), tostring(a20)) |
||
72 | else |
||
73 | if not tmp then |
||
74 | tmp = {} |
||
75 | end |
||
76 | |||
77 | -- This block dynamically rebuilds the tmp array stopping on the first nil. |
||
78 | table.insert(tmp, output) |
||
79 | |||
80 | table.insert(tmp, tostring(a1)) |
||
81 | table.insert(tmp, a2) |
||
82 | table.insert(tmp, a3) |
||
83 | table.insert(tmp, a4) |
||
84 | table.insert(tmp, a5) |
||
85 | table.insert(tmp, a6) |
||
86 | table.insert(tmp, a7) |
||
87 | table.insert(tmp, a8) |
||
88 | table.insert(tmp, a9) |
||
89 | table.insert(tmp, a10) |
||
90 | table.insert(tmp, a11) |
||
91 | table.insert(tmp, a12) |
||
92 | table.insert(tmp, a13) |
||
93 | table.insert(tmp, a14) |
||
94 | table.insert(tmp, a15) |
||
95 | table.insert(tmp, a16) |
||
96 | table.insert(tmp, a17) |
||
97 | table.insert(tmp, a18) |
||
98 | table.insert(tmp, a19) |
||
99 | table.insert(tmp, a20) |
||
100 | while tmp[table.getn(tmp)] == nil do |
||
101 | table.remove(tmp) |
||
102 | end |
||
103 | for k = 1, table.getn(tmp) do |
||
104 | tmp[k] = tostring(tmp[k]) |
||
105 | end |
||
106 | |||
107 | output = table.concat(tmp, " ") |
||
108 | |||
109 | for k,v in pairs(tmp) do |
||
110 | tmp[k] = nil |
||
111 | end |
||
112 | table_setn(tmp, 0) |
||
113 | end |
||
114 | |||
115 | print(output, r, g, b, frame or self.debugFrame, delay) |
||
116 | end |
||
117 | |||
118 | function AceDebug:Debug(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) |
||
119 | AceDebug.CustomDebug(self, nil, nil, nil, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) |
||
120 | end |
||
121 | |||
122 | function AceDebug:IsDebugging() |
||
123 | return self.debugging |
||
124 | end |
||
125 | |||
126 | function AceDebug:SetDebugging(debugging) |
||
127 | self.debugging = debugging |
||
128 | end |
||
129 | |||
130 | -- Takes a number 1-3 |
||
131 | -- Level 1: Critical messages that every user should receive |
||
132 | -- Level 2: Should be used for local debugging (function calls, etc) |
||
133 | -- Level 3: Very verbose debugging, will dump everything and anything |
||
134 | -- If set to nil, you will receive no debug information |
||
135 | function AceDebug:SetDebugLevel(level) |
||
136 | AceDebug:argCheck(level, 1, "number", "nil") |
||
137 | if not level then |
||
138 | self.debuglevel = nil |
||
139 | return |
||
140 | end |
||
141 | if level < 1 or level > 3 then |
||
142 | AceDebug:error("Bad argument #1 to `SetDebugLevel`, must be a number 1-3") |
||
143 | end |
||
144 | self.debuglevel = level |
||
145 | end |
||
146 | |||
147 | function AceDebug:GetDebugLevel() |
||
148 | return self.debuglevel |
||
149 | end |
||
150 | |||
151 | function AceDebug:CustomLevelDebug(level, r, g, b, frame, delay, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) |
||
152 | if not self.debugging or not self.debuglevel then return end |
||
153 | AceDebug:argCheck(level, 1, "number") |
||
154 | if level < 1 or level > 3 then |
||
155 | AceDebug:error("Bad argument #1 to `LevelDebug`, must be a number 1-3") |
||
156 | end |
||
157 | if level > self.debuglevel then return end |
||
158 | |||
159 | local output = string.format("|cff7fff7f(DEBUG) %s:[%s.%3d]|r", tostring(self), date("%H:%M:%S"), math_mod(GetTime(), 1) * 1000) |
||
160 | |||
161 | if string.find(tostring(a1), "%%") then |
||
162 | output = output .. " " .. string.format(tostring(a1), tostring(a2), tostring(a3), tostring(a4), tostring(a5), tostring(a6), tostring(a7), tostring(a8), tostring(a9), tostring(a10), tostring(a11), tostring(a12), tostring(a13), tostring(a14), tostring(a15), tostring(a16), tostring(a17), tostring(a18), tostring(a19), tostring(a20)) |
||
163 | else |
||
164 | if not tmp then |
||
165 | tmp = {} |
||
166 | end |
||
167 | |||
168 | -- This block dynamically rebuilds the tmp array stopping on the first nil. |
||
169 | table.insert(tmp, output) |
||
170 | |||
171 | table.insert(tmp, tostring(a1)) |
||
172 | table.insert(tmp, a2) |
||
173 | table.insert(tmp, a3) |
||
174 | table.insert(tmp, a4) |
||
175 | table.insert(tmp, a5) |
||
176 | table.insert(tmp, a6) |
||
177 | table.insert(tmp, a7) |
||
178 | table.insert(tmp, a8) |
||
179 | table.insert(tmp, a9) |
||
180 | table.insert(tmp, a10) |
||
181 | table.insert(tmp, a11) |
||
182 | table.insert(tmp, a12) |
||
183 | table.insert(tmp, a13) |
||
184 | table.insert(tmp, a14) |
||
185 | table.insert(tmp, a15) |
||
186 | table.insert(tmp, a16) |
||
187 | table.insert(tmp, a17) |
||
188 | table.insert(tmp, a18) |
||
189 | table.insert(tmp, a19) |
||
190 | table.insert(tmp, a20) |
||
191 | while tmp[table.getn(tmp)] == nil do |
||
192 | table.remove(tmp) |
||
193 | end |
||
194 | for k = 1, table.getn(tmp) do |
||
195 | tmp[k] = tostring(tmp[k]) |
||
196 | end |
||
197 | |||
198 | output = table.concat(tmp, " ") |
||
199 | |||
200 | for k,v in pairs(tmp) do |
||
201 | tmp[k] = nil |
||
202 | end |
||
203 | table_setn(tmp, 0) |
||
204 | end |
||
205 | |||
206 | print(output, r, g, b, frame or self.debugFrame, delay) |
||
207 | end |
||
208 | |||
209 | function AceDebug:LevelDebug(level, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) |
||
210 | if not self.debugging or not self.debuglevel then return end |
||
211 | AceDebug:argCheck(level, 1, "number") |
||
212 | if level < 1 or level > 3 then |
||
213 | AceDebug:error("Bad argument #1 to `LevelDebug`, must be a number 1-3") |
||
214 | end |
||
215 | if level > self.debuglevel then return end |
||
216 | |||
217 | AceDebug.CustomLevelDebug(self, level, nil, nil, nil, nil, nil, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20) |
||
218 | end |
||
219 | |||
220 | |||
221 | local options |
||
222 | function AceDebug:GetAceOptionsDataTable(target) |
||
223 | if not options then |
||
224 | options = { |
||
225 | debug = { |
||
226 | name = DEBUGGING, |
||
227 | desc = TOGGLE_DEBUGGING, |
||
228 | type = "toggle", |
||
229 | get = "IsDebugging", |
||
230 | set = "SetDebugging", |
||
231 | order = -2, |
||
232 | } |
||
233 | } |
||
234 | end |
||
235 | return options |
||
236 | end |
||
237 | AceLibrary:Register(AceDebug, MAJOR_VERSION, MINOR_VERSION, AceDebug.activate) |
||
238 | AceDebug = AceLibrary(MAJOR_VERSION) |