tekkub / spew
- Source
- Commits
- Network (0)
- Issues (0)
- Downloads (6)
- Wiki (1)
- Graphs
-
Tree:
89c540e
spew / Spew.lua
| ed0ac59d » | tekkub | 2008-08-02 | 1 | local TABLEITEMS, TABLEDEPTH = 5, 1 | |
| 7ce92109 » | tekkub | 2008-11-10 | 2 | local tostring, TableToString = tostring | |
| 2d081e06 » | tekkub | 2008-08-02 | 3 | ||
| 4 | local panel = LibStub("tekPanel-Auction").new("SpewPanel", "Spew") | ||||
| 0d207d13 » | tekkub | 2008-08-02 | 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 | 18 | elseif delta < 0 then | |
| 0d207d13 » | tekkub | 2008-08-02 | 19 | if IsShiftKeyDown() then frame:ScrollToBottom() | |
| 20 | else for i=1,4 do frame:ScrollDown() end end | ||||
| c25a7021 » | tekkub | 2008-08-02 | 21 | end | |
| 0d207d13 » | tekkub | 2008-08-02 | 22 | end) | |
| 23 | |||||
| 24 | |||||
| 2d081e06 » | tekkub | 2008-08-02 | 25 | local b = LibStub("tekKonfig-Button").new(cf, "TOPRIGHT", cf, "BOTTOMRIGHT", -155, -3) | |
| 16812ef4 » | tekkub | 2008-10-22 | 26 | b:SetText("Clear") | |
| 27 | b:SetScript("OnClick", function() cf:Clear() end) | ||||
| 28 | |||||
| 29 | local function Print(text, frame) | ||||
| 0d207d13 » | tekkub | 2008-08-02 | 30 | if not text or text:len() == 0 then text = " " end | |
| ed0ac59d » | tekkub | 2008-08-02 | 31 | (frame or cf):AddMessage(text) | |
| 0d207d13 » | tekkub | 2008-08-02 | 32 | end | |
| ed0ac59d » | tekkub | 2008-08-02 | 33 | ||
| 34 | |||||
| 35 | local colors = {boolean = "|cffff9100", number = "|cffff7fff", ["nil"] = "|cffff7f7f"} | ||||
| 2d081e06 » | tekkub | 2008-08-02 | 36 | local noescape = {["\a"] = "a", ["\b"] = "b", ["\f"] = "f", ["\n"] = "n", ["\r"] = "r", ["\t"] = "t", ["\v"] = "v"} | |
| 1034f089 » | tekkub | 2008-10-08 | 37 | local function escape(c) return "\\".. (noescape[c] or c:byte()) end | |
| 38 | local function pretty_tostring(value, depth) | ||||
| 7ce92109 » | tekkub | 2008-11-10 | 39 | depth = depth or 0 | |
| 40 | local t = type(value) | ||||
| 2d081e06 » | tekkub | 2008-08-02 | 41 | if t == "string" then return '|cff00ff00"'..value:gsub("|", "||"):gsub("([\001-\031\128-\255])", escape)..'"|r' | |
| 1034f089 » | tekkub | 2008-10-08 | 42 | elseif t == "table" then | |
| 2d081e06 » | tekkub | 2008-08-02 | 43 | if depth > TABLEDEPTH then return "|cff9f9f9f{...}|r" | |
| 7ce92109 » | tekkub | 2008-11-10 | 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 | 47 | else return tostring(value) end | |
| 48 | end | ||||
| ed0ac59d » | tekkub | 2008-08-02 | 49 | ||
| 50 | |||||
| 2d081e06 » | tekkub | 2008-08-02 | 51 | function TableToString(t, lasti, items, depth) | |
| 7ce92109 » | tekkub | 2008-11-10 | 52 | items = items or 0 | |
| 53 | depth = depth or 0 | ||||
| ed0ac59d » | tekkub | 2008-08-02 | 54 | if items > TABLEITEMS then return "...|cff9f9f9f}|r" end | |
| 7ce92109 » | tekkub | 2008-11-10 | 55 | local i,v = next(t, lasti) | |
| ed0ac59d » | tekkub | 2008-08-02 | 56 | if items == 0 then | |
| 7ce92109 » | tekkub | 2008-11-10 | 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 | 59 | else return "|cff9f9f9f{|cff7fd5ff"..tostring(i).."|r = "..pretty_tostring(v, depth).."|cff9f9f9f}|r" end | |
| 7ce92109 » | tekkub | 2008-11-10 | 60 | end | |
| ed0ac59d » | tekkub | 2008-08-02 | 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 | 62 | return "|cff7fd5ff"..tostring(i).."|r = "..pretty_tostring(v, depth).."|cff9f9f9f}|r" | |
| 63 | end | ||||
| 2d081e06 » | tekkub | 2008-08-02 | 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 | 70 | ||
| 71 | |||||
| d2eb6feb » | tekkub | 2008-08-02 | 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 | 74 | local function pcallhelper(success, ...) if success then return string.join(", ", ArgsToString(...)) end end | |
| d2eb6feb » | tekkub | 2008-08-02 | 75 | function Spew(input, a1, ...) | |
| 77eae10a » | tekkub | 2008-09-14 | 76 | if select('#', ...) == 0 then | |
| ed0ac59d » | tekkub | 2008-08-02 | 77 | if type(a1) == "table" then | |
| 78 | if type(rawget(a1, 0)) == "userdata" and type(a1.GetObjectType) == "function" then | ||||
| d2eb6feb » | tekkub | 2008-08-02 | 79 | -- We've got a frame! | |
| 80 | Print("|cffffea00<"..a1:GetObjectType()..":"..(a1:GetName() or input.."(anon)").."|r") | ||||
| 1d434e97 » | tekkub | 2008-08-02 | 81 | local sorttable = {} | |
| d2eb6feb » | tekkub | 2008-08-02 | 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 | 91 | else Print(" |cff7fd5ff"..tostring(i).."|r = "..pretty_tostring(v)) end | |
| 92 | end | ||||
| d2eb6feb » | tekkub | 2008-08-02 | 93 | Print("|cffffea00>|r") | |
| 0d207d13 » | tekkub | 2008-08-02 | 94 | ShowUIPanel(panel) | |
| 95 | else | ||||
| d2eb6feb » | tekkub | 2008-08-02 | 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 | 102 | Print("|cff9f9f9f} -- "..input.."|r") | |
| d2eb6feb » | tekkub | 2008-08-02 | 103 | ShowUIPanel(panel) | |
| 0d207d13 » | tekkub | 2008-08-02 | 104 | end | |
| d2eb6feb » | tekkub | 2008-08-02 | 105 | else Print("|cff999999"..input.."|r => "..pretty_tostring(a1), DEFAULT_CHAT_FRAME) end | |
| 77eae10a » | tekkub | 2008-09-14 | 106 | else | |
| ed0ac59d » | tekkub | 2008-08-02 | 107 | Print("|cff999999"..input.."|r => "..string.join(", ", ArgsToString(a1, ...)), DEFAULT_CHAT_FRAME) | |
| 77eae10a » | tekkub | 2008-09-14 | 108 | end | |
| ed0ac59d » | tekkub | 2008-08-02 | 109 | end | |
| 110 | |||||
| 111 | |||||
| 112 | SLASH_SPEW1 = "/spew" | ||||
| 113 | function SlashCmdList.SPEW(text) | ||||
| 114 | input = text:trim():match("^(.-);*$") | ||||
| 2d081e06 » | tekkub | 2008-08-02 | 115 | if input == "" then ShowUIPanel(panel) | |
| 0d207d13 » | tekkub | 2008-08-02 | 116 | elseif input == "mouse" then | |
| 01625ed8 » | tekkub | 2008-10-26 | 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 | 124 | local f, err = loadstring(string.format("Spew(%q, %s)", input, input)) | |
| 3425fd99 » | tekkub | 2008-10-08 | 125 | if f then f() else Print("|cffff0000Error:|r "..err) end | |
| 0d207d13 » | tekkub | 2008-08-02 | 126 | end | |
| 127 | end | ||||
| ed0ac59d » | tekkub | 2008-08-02 | 128 | ||
| d2eb6feb » | tekkub | 2008-08-02 | 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 | |||||

