-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGH_Debug.lua
More file actions
executable file
·160 lines (136 loc) · 4.34 KB
/
GH_Debug.lua
File metadata and controls
executable file
·160 lines (136 loc) · 4.34 KB
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
local DT = {}
local function GetDebugChatFrame()
local found
for i = 1, NUM_CHAT_WINDOWS do
local name = GetChatWindowInfo(i)
if name == "GH Debug" then
found = i
break
end
end
if found then
return _G["ChatFrame" .. found]
else
return FCF_OpenNewWindow("GH Debug", true)
end
end
local function WriteMessage(self, msg)
GetDebugChatFrame():AddMessage(msg)
end
local function DevTools_InitFunctionCache(context)
local ret = {}
for _, k in ipairs(DT.functionSymbols) do
local v = getglobal(k)
if (type(v) == "function") then
ret[v] = "[" .. k .. "]"
end
end
for k, v in pairs(getfenv(0)) do
if (type(v) == "function") then
if (not ret[v]) then
ret[v] = "[" .. k .. "]"
end
end
end
return ret
end
local function DevTools_InitUserdataCache(context)
local ret = {}
for _, k in ipairs(DT.userdataSymbols) do
local v = getglobal(k)
if (type(v) == "table") then
local u = rawget(v, 0)
if (type(u) == "userdata") then
ret[u] = k .. "[0]"
end
end
end
for k, v in pairs(getfenv(0)) do
if (type(v) == "table") then
local u = rawget(v, 0)
if (type(u) == "userdata") then
if (not ret[u]) then
ret[u] = k .. "[0]"
end
end
end
end
return ret
end
local function DevTools_Cache_Function(self, value, newName)
if (not self.fCache) then
self.fCache = DevTools_InitFunctionCache(self)
end
local name = self.fCache[value]
if ((not name) and newName) then
self.fCache[value] = newName
end
return name
end
local function DevTools_Cache_Userdata(self, value, newName)
if (not self.uCache) then
self.uCache = DevTools_InitUserdataCache(self)
end
local name = self.uCache[value]
if ((not name) and newName) then
self.uCache[value] = newName
end
return name
end
local function DevTools_Cache_Table(self, value, newName)
if (not self.tCache) then
self.tCache = {}
end
local name = self.tCache[value]
if ((not name) and newName) then
self.tCache[value] = newName
end
return name
end
local function DevTools_Cache_Nil(self, value, newName)
return nil
end
local function Pick_Cache_Function(func, setting)
if (setting) then
return func
else
return DevTools_Cache_Nil
end
end
function GearHelper:DevToolsDump(value, startKey)
local context = {
depth = 0,
key = startKey
}
context.GetTableName = Pick_Cache_Function(DevTools_Cache_Table, DEVTOOLS_USE_TABLE_CACHE)
context.GetFunctionName = Pick_Cache_Function(DevTools_Cache_Function, DEVTOOLS_USE_FUNCTION_CACHE)
context.GetUserdataName = Pick_Cache_Function(DevTools_Cache_Userdata, DEVTOOLS_USE_USERDATA_CACHE)
context.Write = WriteMessage
DevTools_RunDump(value, context)
end
function GearHelper:Print(object, debugType)
local file, ln = strmatch(debugstack(2, 1, 0), "([%w_]*%.lua).*%:(%d+)")
if (GearHelper.db.profile.debug.bypassAll or (debugType == nil and GearHelper.db.profile.debug.general) or GearHelper.db.profile.debug[debugType]) then
local prefix = debugType and "[" .. debugType .. "] " or ""
if type(object) == "table" then
GetDebugChatFrame():AddMessage(WrapTextInColorCode(prefix .. "[GearHelper] ", "FF00FF96") .. WrapTextInColorCode(tostring(file) .. ":" .. tostring(ln), "FF9482C9") .. "\n-------------- TABLE --------------\n")
GearHelper:DevToolsDump(object)
GetDebugChatFrame():AddMessage("-------------- ENDTABLE -----------")
else
GetDebugChatFrame():AddMessage(WrapTextInColorCode(prefix .. "[GearHelper] ", "FF00FF96") .. WrapTextInColorCode(tostring(file) .. ":" .. tostring(ln), "FF9482C9") .. " - " .. tostring(object))
end
end
end
DT.functionSymbols = {}
DT.userdataSymbols = {}
local funcSyms = DT.functionSymbols
local userSyms = DT.userdataSymbols
for k,v in pairs(getfenv(0)) do
if (type(v) == 'function') then
table.insert(funcSyms, k);
elseif (type(v) == 'table') then
if (type(rawget(v,0)) == 'userdata') then
table.insert(userSyms, k);
end
end
end