-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathCube.lua
287 lines (245 loc) · 7.16 KB
/
Cube.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
---------------------------------------------------------------------------------------------------
-- Cube Main
---------------------------------------------------------------------------------------------------
-- Addon Initialize
IGAS:NewAddon("Cube")
import "System"
import "System.Widget"
-- Localization
L = IGAS:NewLocale("Cube")
-- Logger
Log = IGAS:NewLogger("Cube")
Log.LogLevel = 2
Log:SetPrefix(1, "[Cube:Debug]")
Log:SetPrefix(2, "[Cube:Info]")
Log:AddHandler(print)
GRN ='|cff20ff20'
YEL ='|cffffff00'
RED ='|cffff0000'
WHT ='|cffffffff'
BLU ='|cff8888ff'
DRKBLU ='|cff1b0495'
ORN ='|cffff9C00'
GRY ='|cffA0A0A0'
-- Binding Text
_G.BINDING_HEADER_CUBE = L["Cube"]
_G.BINDING_NAME_CUBE_CODE = L["Simple Dev Tool"]
_G.BINDING_NAME_CUBE_BUGLIST = L["Simple Bug List"]
_G.BINDING_NAME_CUBE_DEBUG = L["Simple Debug Tool"]
_G.BINDING_NAME_CUBE_LOGVIEW = L["Simple Log View"]
_G.BINDING_NAME_CUBE_BROWSER = L["Simple Browser"]
_G.Cube = {}
Cube = _G.Cube
function _Addon:OnLoad()
-- SavedVariables
self:AddSavedVariable("CubeSave")
self:AddSavedVariable("CubeSavePerCharacter")
-- Slash command
self:AddSlashCmd("/cube")
end
function _Addon:OnSlashCmd()
Log(2, "/cube code ("..L["Open the code editor"]..")")
Log(2, "/cube bug ("..L["Open the buglist"]..")")
Log(2, "/cube debug ("..L["Open the debug tool"]..")")
Log(2, "/cube log ("..L["Open the log view"]..")")
Log(2, "/cube br ("..L["Open the igas browser"]..")")
end
-- Functions
function GetErrMsg(err)
if not err or err == "" then
return
end
-- Get the full backtrace
local real =
err:find("^.-([^\\]+\\)([^\\]-)(:%d+):(.*)$") or
err:find("^%[string \".-([^\\]+\\)([^\\]-)\"%](:%d+):(.*)$") or
err:find("^%[string (\".-\")%](:%d+):(.*)$") or err:find("^%[C%]:(.*)$")
err = err .. "\n" .. debugstack(real and 4 or 3)
local errorType = "error"
-- Normalize the full paths into last directory component and filename.
local errmsg = ""
for trace in err:gmatch("(.-)\n") do
local match, found, path, file, line, msg, _
found = false
-- "Interface\AddOns\path\to\file.lua:linenum:message"
if not found then
match, _, path, file, line, msg = trace:find("^.-[A%.][d%.][d%.][Oo]ns\\(.*)([^\\]-)(:%d+):(.*)$")
if match then
found = true
local addon = path:gsub("\\.*$", "")
local addonObject = _G[addon]
if not addonObject then
addonObject = _G[addon:match("^[^_]+_(.*)$")]
end
local version, revision = nil, nil
local objectName = addon:upper()
if not version then version = _G[objectName .. "_VERSION"] end
if not revision then revision = _G[objectName .. "_REVISION"] or _G[objectName .. "_REV"] end
if not version then version = GetAddOnMetadata(addon, "Version") end
if not version and revision then version = revision
elseif type(version) == "string" and revision and not version:find(revision) then
version = version .. "." .. revision
end
if version then
path = addon .. "-" .. version .. path:gsub("^[^\\]*", "")
end
end
end
-- "path\to\file.lua:linenum:message"
if not found then
match, _, path, file, line, msg = trace:find("^.-([^\\]+\\)([^\\])(:%d+):(.*)$")
if match then
found = true
end
end
-- "[string \"path\\to\\file.lua:<foo>\":linenum:message"
if not found then
match, _, path, file, line, msg = trace:find("^%[string \".-([^\\]+\\)([^\\]-)\"%](:%d+):(.*)$")
if match then
found = true
end
end
-- "[string \"FOO\":linenum:message"
if not found then
match, _, file, line, msg = trace:find("^%[string (\".-\")%](:%d+):(.*)$")
if match then
found = true
path = "<string>:"
end
end
-- "[C]:message"
if not found then
match, _, msg = trace:find("^%[C%]:(.*)$")
if match then
found = true
path = "<in C code>"
file = ""
line = ""
end
end
-- Anything else
if not found then
path = trace--"<unknown>"
file = ""
line = ""
msg = line
end
-- Add it to the formatted error
errmsg = errmsg .. path .. file .. line .. ":" .. msg .. "\n"
end
return errmsg
end
local function orderKey(t1, t2)
if t1 and t2 then
if type(t1) == "number" and type(t2) == "number" then
return t1 < t2
elseif type(t1) == "string" and type(t2) ~= "string" then
return true
elseif type(t1) ~= "string" and type(t2) == "string" then
return false
else
return tostring(t1) < tostring(t2)
end
else
return tostring(t1) < tostring(t2)
end
end
function pairsByKeys (t, f)
local a = {}
for n in pairs(t) do table.insert(a, n) end
table.sort(a, f or orderKey)
local i = 0 -- iterator variable
local iter = function () -- iterator function
i = i + 1
if a[i] == nil then
return nil
else
return a[i], t[a[i]]
end
end
return iter
end
local readedTable = {}
function Format(v, format)
if type(v) == "string" and format then
return string.format("%q", v)
elseif type(v) == "table" then
wipe(readedTable)
local ret = SerializeTable(v)
wipe(readedTable)
return ret
else
return tostring(v)
end
end
function SerializeTable(t)
readedTable[t] = true
local str = "{\n"
for name, value in pairs(t) do
if type(name) == "string" or type(name) == "number" then
name = Format(name, true)
if type(value) == "table" then
if readedTable[value] then
str = str.." ["..name.."] = "..tostring(value)..",\n"
else
str = str.." ["..name.."] = "..string.gsub(SerializeTable(value), "\n", "\n ")..",\n"
end
elseif type(value) == "number" or type(value) == "string" then
str = str.." ["..name.."] = "..Format(value, true)..",\n"
elseif type(value) == "boolean" then
value = (value and true) or false
str = str.." ["..name.."] = "..Format(value, true)..",\n"
end
end
end
str = str.."}"
return str
end
local LOCAL_ToStringAllTemp = {}
function tostringall(...)
local n = select('#', ...)
-- Simple versions for common argument counts
if (n == 1) then
return Format(...)
elseif (n == 2) then
local a, b = ...
return Format(a), Format(b)
elseif (n == 3) then
local a, b, c = ...
return Format(a), Format(b), Format(c)
elseif (n == 0) then
return
end
local needfix
for i = 1, n do
local v = select(i, ...)
if (type(v) ~= "string") then
needfix = i
break
end
end
if (not needfix) then return ... end
wipe(LOCAL_ToStringAllTemp)
for i = 1, needfix - 1 do
LOCAL_ToStringAllTemp[i] = select(i, ...)
end
for i = needfix, n do
LOCAL_ToStringAllTemp[i] = Format(select(i, ...))
end
return unpack(LOCAL_ToStringAllTemp)
end
local LOCAL_PrintHandler =
function(...)
DEFAULT_CHAT_FRAME:AddMessage(strjoin(" ", tostringall(...)))
end
function setprinthandler(func)
if (type(func) ~= "function") then
error("Invalid print handler")
else
LOCAL_PrintHandler = func
end
end
function getprinthandler() return LOCAL_PrintHandler end
function print(...)
LOCAL_PrintHandler(...)
end