-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.lua
128 lines (95 loc) · 3.53 KB
/
main.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
local NAME, T = ...
local function box(status, ...) return status, {...} end
local context = {
depth = 0,
GetTableName = function() return nil end,
GetFunctionName = function() return nil end,
GetUserdataName = function() return nil end,
Write = function(self, message)
self.output[#self.output + 1] = message
end
}
local function exec(str)
if type(str) ~= "string" then return "<<< Invalid Input >>>" end
local func, err = loadstring("return " .. str)
if not func then return tostring(err) end
local success, values = box(pcall(func))
if not success then return tostring(values[1]) end
context.output = {}
DevTools_RunDump(values, context)
return table.concat(context.output, "\n")
end
local frame
local function create()
if frame then return frame end
frame = CreateFrame("Frame", nil, UIParent)
frame:EnableMouse(true)
frame:SetMovable(true)
frame:SetWidth(400)
frame:SetHeight(300)
frame:SetPoint("CENTER")
frame:SetBackdrop({
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true,
edgeSize = 16,
tileSize = 32,
insets = {
left = 2.5,
right = 2.5,
top = 2.5,
bottom = 2.5
}
})
frame:SetScript("OnMouseDown", function(f) f:StartMoving() end)
frame:SetScript("OnMouseUp", function(f) f:StopMovingOrSizing() end)
frame.label = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
frame.label:SetWidth(400)
frame.label:SetHeight(16)
frame.label:SetPoint("TOP", frame, "TOP", 0, -5)
frame.label:SetText("LuaRunner")
frame.label:SetJustifyH("CENTER")
frame.close = CreateFrame("Button", nil, frame, "UIPanelCloseButton")
frame.close:SetPoint("TOPRIGHT", frame, "TOPRIGHT", -1, -1)
frame.close:SetScript("OnClick", function() frame:Hide() end)
local function escape(f) f:ClearFocus() end
frame.input = CreateFrame("EditBox", nil, frame, "InputBoxTemplate")
frame.input:SetPoint("TOP", frame.label, "BOTTOM", 0, -5)
frame.input:SetPoint("LEFT", frame, "LEFT", 10, 0)
frame.input:SetPoint("RIGHT", frame, "RIGHT", -10, 0)
frame.input:SetHeight(20)
frame.input:SetAutoFocus(false)
frame.input:SetScript("OnEscapePressed", escape)
frame.output = CreateFrame("ScrollFrame", nil, frame, "InputScrollFrameTemplate")
frame.output:SetPoint("TOPLEFT", frame.input, "BOTTOMLEFT", 0, -5)
frame.output:SetPoint("TOPRIGHT", frame.input, "BOTTOMRIGHT", 0, -5)
frame.output:SetPoint("BOTTOM", frame, "BOTTOM", 0, 10)
frame.output.EditBox:SetPoint("RIGHT", frame.output, "RIGHT", 0, 0)
frame.output.CharCount:Hide()
local function update()
local result = exec(frame.input:GetText())
if type(result) ~= "string" then
result = "<<< exec returned non-string value >>>"
end
frame.output.EditBox:SetText(result)
end
frame.input:SetScript("OnTextChanged", function(f, user)
if not user then return end
update()
end)
frame:SetScript("OnShow", function(f)
f.tick = C_Timer.NewTicker(0.1, update)
end)
frame:SetScript("OnHide", function(f)
if f.tick then f.tick:Cancel() end
end)
frame:Hide()
return frame
end
for i, v in ipairs({"luarunner", "lr"}) do
_G["SLASH_" .. NAME:upper() .. i] = "/" .. v
end
SlashCmdList[NAME:upper()] = function(msg, editbox)
LoadAddOn("Blizzard_DebugTools")
create():Show()
end