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