tekkub / spew

WoW Addon - Spews out lua

This URL has Read+Write access

spew / Spew.lua
ed0ac59d » tekkub 2008-08-02 And so it begins... 1 local TABLEITEMS, TABLEDEPTH = 5, 1
7ce92109 » tekkub 2008-11-10 Don't recurse too deeply in... 2 local tostring, TableToString = tostring
2d081e06 » tekkub 2008-08-02 Make output have pretty colors 3
4 local panel = LibStub("tekPanel-Auction").new("SpewPanel", "Spew")
0d207d13 » tekkub 2008-08-02 Add in panel, all multi-lin... 5 local cf = CreateFrame("ScrollingMessageFrame", nil, panel)
6 cf:SetPoint("TOPLEFT", 25, -75)
7 cf:SetPoint("BOTTOMRIGHT", -15, 40)
8 cf:SetMaxLines(1000)
9 cf:SetFontObject(ChatFontSmall)
10 cf:SetJustifyH("LEFT")
11 cf:SetFading(false)
12 cf:EnableMouseWheel(true)
13 cf:SetScript("OnHide", cf.ScrollToBottom)
14 cf:SetScript("OnMouseWheel", function(frame, delta)
15 if delta > 0 then
16 if IsShiftKeyDown() then frame:ScrollToTop()
17 else for i=1,4 do frame:ScrollUp() end end
c25a7021 » tekkub 2008-08-02 Scroll 4 lines at a time, t... 18 elseif delta < 0 then
0d207d13 » tekkub 2008-08-02 Add in panel, all multi-lin... 19 if IsShiftKeyDown() then frame:ScrollToBottom()
20 else for i=1,4 do frame:ScrollDown() end end
c25a7021 » tekkub 2008-08-02 Scroll 4 lines at a time, t... 21 end
0d207d13 » tekkub 2008-08-02 Add in panel, all multi-lin... 22 end)
23
24
2d081e06 » tekkub 2008-08-02 Make output have pretty colors 25 local b = LibStub("tekKonfig-Button").new(cf, "TOPRIGHT", cf, "BOTTOMRIGHT", -155, -3)
16812ef4 » tekkub 2008-10-22 Add button to clear spewings 26 b:SetText("Clear")
27 b:SetScript("OnClick", function() cf:Clear() end)
28
29 local function Print(text, frame)
0d207d13 » tekkub 2008-08-02 Add in panel, all multi-lin... 30 if not text or text:len() == 0 then text = " " end
ed0ac59d » tekkub 2008-08-02 And so it begins... 31 (frame or cf):AddMessage(text)
0d207d13 » tekkub 2008-08-02 Add in panel, all multi-lin... 32 end
ed0ac59d » tekkub 2008-08-02 And so it begins... 33
34
35 local colors = {boolean = "|cffff9100", number = "|cffff7fff", ["nil"] = "|cffff7f7f"}
2d081e06 » tekkub 2008-08-02 Make output have pretty colors 36 local noescape = {["\a"] = "a", ["\b"] = "b", ["\f"] = "f", ["\n"] = "n", ["\r"] = "r", ["\t"] = "t", ["\v"] = "v"}
1034f089 » tekkub 2008-10-08 Don't escape out special ch... 37 local function escape(c) return "\\".. (noescape[c] or c:byte()) end
38 local function pretty_tostring(value, depth)
7ce92109 » tekkub 2008-11-10 Don't recurse too deeply in... 39 depth = depth or 0
40 local t = type(value)
2d081e06 » tekkub 2008-08-02 Make output have pretty colors 41 if t == "string" then return '|cff00ff00"'..value:gsub("|", "||"):gsub("([\001-\031\128-\255])", escape)..'"|r'
1034f089 » tekkub 2008-10-08 Don't escape out special ch... 42 elseif t == "table" then
2d081e06 » tekkub 2008-08-02 Make output have pretty colors 43 if depth > TABLEDEPTH then return "|cff9f9f9f{...}|r"
7ce92109 » tekkub 2008-11-10 Don't recurse too deeply in... 44 elseif type(rawget(value, 0)) == "userdata" and type(value.GetObjectType) == "function" then return "|cffffea00<"..value:GetObjectType()..":"..(value:GetName() or "(anon)")..">|r"
45 else return "|cff9f9f9f"..string.join(", ", TableToString(value, nil, nil, depth+1)).."|r" end
46 elseif colors[t] then return colors[t]..tostring(value).."|r"
2d081e06 » tekkub 2008-08-02 Make output have pretty colors 47 else return tostring(value) end
48 end
ed0ac59d » tekkub 2008-08-02 And so it begins... 49
50
2d081e06 » tekkub 2008-08-02 Make output have pretty colors 51 function TableToString(t, lasti, items, depth)
7ce92109 » tekkub 2008-11-10 Don't recurse too deeply in... 52 items = items or 0
53 depth = depth or 0
ed0ac59d » tekkub 2008-08-02 And so it begins... 54 if items > TABLEITEMS then return "...|cff9f9f9f}|r" end
7ce92109 » tekkub 2008-11-10 Don't recurse too deeply in... 55 local i,v = next(t, lasti)
ed0ac59d » tekkub 2008-08-02 And so it begins... 56 if items == 0 then
7ce92109 » tekkub 2008-11-10 Don't recurse too deeply in... 57 if next(t, i) then return "|cff9f9f9f{|cff7fd5ff"..tostring(i).."|r = "..pretty_tostring(v, depth), TableToString(t, i, 1, depth)
58 elseif v == nil then return "|cff9f9f9f{}|r"
2d081e06 » tekkub 2008-08-02 Make output have pretty colors 59 else return "|cff9f9f9f{|cff7fd5ff"..tostring(i).."|r = "..pretty_tostring(v, depth).."|cff9f9f9f}|r" end
7ce92109 » tekkub 2008-11-10 Don't recurse too deeply in... 60 end
ed0ac59d » tekkub 2008-08-02 And so it begins... 61 if next(t, i) then return "|cff7fd5ff"..tostring(i).."|r = "..pretty_tostring(v, depth), TableToString(t, i, items+1, depth) end
7ce92109 » tekkub 2008-11-10 Don't recurse too deeply in... 62 return "|cff7fd5ff"..tostring(i).."|r = "..pretty_tostring(v, depth).."|cff9f9f9f}|r"
63 end
2d081e06 » tekkub 2008-08-02 Make output have pretty colors 64
65
66 local function ArgsToString(a1, ...)
67 if select('#', ...) < 1 then return pretty_tostring(a1)
68 else return pretty_tostring(a1), ArgsToString(...) end
69 end
ed0ac59d » tekkub 2008-08-02 And so it begins... 70
71
d2eb6feb » tekkub 2008-08-02 Implement frame function ca... 72 local blist, input = {GetDisabledFontObject = true, GetHighlightFontObject = true, GetNormalFontObject = true}
73 local function downcasesort(a,b) return a and b and tostring(a):lower() < tostring(b):lower() end
264fde51 » tekkub 2008-08-02 Sort tables by index before... 74 local function pcallhelper(success, ...) if success then return string.join(", ", ArgsToString(...)) end end
d2eb6feb » tekkub 2008-08-02 Implement frame function ca... 75 function Spew(input, a1, ...)
77eae10a » tekkub 2008-09-14 Echo back the input when ou... 76 if select('#', ...) == 0 then
ed0ac59d » tekkub 2008-08-02 And so it begins... 77 if type(a1) == "table" then
78 if type(rawget(a1, 0)) == "userdata" and type(a1.GetObjectType) == "function" then
d2eb6feb » tekkub 2008-08-02 Implement frame function ca... 79 -- We've got a frame!
80 Print("|cffffea00<"..a1:GetObjectType()..":"..(a1:GetName() or input.."(anon)").."|r")
1d434e97 » tekkub 2008-08-02 Dot dot dot 81 local sorttable = {}
d2eb6feb » tekkub 2008-08-02 Implement frame function ca... 82 for i in pairs(a1) do table.insert(sorttable, i) end
83 for i in pairs(getmetatable(a1).__index) do table.insert(sorttable, i) end
84 table.sort(sorttable, downcasesort)
85 for _,i in ipairs(sorttable) do
86 local v, output = a1[i]
87 if type(v) == "function" and type(i) == "string" and not blist[i] and (i:find("^Is") or i:find("^Can") or i:find("^Get")) then
88 output = pcallhelper(pcall(v, a1))
89 end
90 if output then Print(" |cff7fd5ff"..tostring(i).."|r => "..output)
bf8537e3 » tekkub 2008-08-02 Increase indents a bit 91 else Print(" |cff7fd5ff"..tostring(i).."|r = "..pretty_tostring(v)) end
92 end
d2eb6feb » tekkub 2008-08-02 Implement frame function ca... 93 Print("|cffffea00>|r")
0d207d13 » tekkub 2008-08-02 Add in panel, all multi-lin... 94 ShowUIPanel(panel)
95 else
d2eb6feb » tekkub 2008-08-02 Implement frame function ca... 96 -- Normal table
97 Print("|cff9f9f9f{ -- "..input.."|r")
98 local sorttable = {}
99 for i in pairs(a1) do table.insert(sorttable, i) end
100 table.sort(sorttable, downcasesort)
101 for _,i in ipairs(sorttable) do Print(" |cff7fd5ff"..tostring(i).."|r = "..pretty_tostring(a1[i], 1)) end
7ce92109 » tekkub 2008-11-10 Don't recurse too deeply in... 102 Print("|cff9f9f9f} -- "..input.."|r")
d2eb6feb » tekkub 2008-08-02 Implement frame function ca... 103 ShowUIPanel(panel)
0d207d13 » tekkub 2008-08-02 Add in panel, all multi-lin... 104 end
d2eb6feb » tekkub 2008-08-02 Implement frame function ca... 105 else Print("|cff999999"..input.."|r => "..pretty_tostring(a1), DEFAULT_CHAT_FRAME) end
77eae10a » tekkub 2008-09-14 Echo back the input when ou... 106 else
ed0ac59d » tekkub 2008-08-02 And so it begins... 107 Print("|cff999999"..input.."|r => "..string.join(", ", ArgsToString(a1, ...)), DEFAULT_CHAT_FRAME)
77eae10a » tekkub 2008-09-14 Echo back the input when ou... 108 end
ed0ac59d » tekkub 2008-08-02 And so it begins... 109 end
110
111
112 SLASH_SPEW1 = "/spew"
113 function SlashCmdList.SPEW(text)
114 input = text:trim():match("^(.-);*$")
2d081e06 » tekkub 2008-08-02 Make output have pretty colors 115 if input == "" then ShowUIPanel(panel)
0d207d13 » tekkub 2008-08-02 Add in panel, all multi-lin... 116 elseif input == "mouse" then
01625ed8 » tekkub 2008-10-26 Change '/spewmouse' to '/sp... 117 local t, f = {}, EnumerateFrames()
118 while f do
119 if f:IsVisible() and MouseIsOver(f) then table.insert(t, f:GetName() or "<Anon>") end
120 f = EnumerateFrames(f)
121 end
122 Spew("Visible frames under mouse", t)
123 else
0d207d13 » tekkub 2008-08-02 Add in panel, all multi-lin... 124 local f, err = loadstring(string.format("Spew(%q, %s)", input, input))
3425fd99 » tekkub 2008-10-08 Fix error with spewings tha... 125 if f then f() else Print("|cffff0000Error:|r "..err) end
0d207d13 » tekkub 2008-08-02 Add in panel, all multi-lin... 126 end
127 end
ed0ac59d » tekkub 2008-08-02 And so it begins... 128
d2eb6feb » tekkub 2008-08-02 Implement frame function ca... 129
130 --[[
131 -- Testing code to help find crashes
132 TEKX = TEKX or 0
133 local blist, input = {GetDisabledFontObject = true, GetHighlightFontObject = true, GetNormalFontObject = true}
134 local function downcasesort(a,b) return a and b and tostring(a):lower() < tostring(b):lower() end
135 local a1=PlayerFrame
136 local sorttable = {}
137 for i in pairs(a1) do table.insert(sorttable, i) end
138 for i in pairs(getmetatable(a1).__index) do table.insert(sorttable, i) end
139 table.sort(sorttable, downcasesort)
140 for j,i in ipairs(sorttable) do
141 local v, output = a1[i]
142 if j > TEKX and type(v) == "function" and type(i) == "string" and not blist[i] and i:find("^Get") then
143 TEKX = j
144 ChatFrame1:AddMessage("Testing "..TEKX.." - "..i)
145 output = pcall(v, a1)
146 return
147 end
148 end
149 ChatFrame1:AddMessage("Done testing")
150 ]]
151