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