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