-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlankSlate.lua
More file actions
143 lines (131 loc) · 4.42 KB
/
BlankSlate.lua
File metadata and controls
143 lines (131 loc) · 4.42 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
do
local addon, namespace = ...
_G[addon] = _G[addon] or {}
setfenv(1, setmetatable(namespace, { __index = _G }))
end
--BlankSlate should never remove these globals.
keepers = {
--Lua globals
_G = true,
_VERSION = true,
--Lua library tables
bit = true,
coroutine = true,
math = true,
string = true,
table = true,
--C API tables
C_AdventureJournal = true,
C_BlackMarket = true,
C_Commentator = true,
C_Garrison = true,
C_Heirloom = true,
C_LFGList = true,
C_LootHistory = true,
C_LossOfControl = true,
C_MapBar = true,
C_MountJournal = true,
C_NewItems = true,
C_PetBattles = true,
C_PetJournal = true,
C_ProductChoice = true,
C_Questline = true,
C_RecruitAFriend = true,
C_Scenario = true,
C_Social = true,
C_StorePublic = true,
C_TaskQuest = true,
C_Timer = true,
C_ToyBox = true,
C_Trophy = true,
C_Vignettes = true,
C_WowTokenPublic = true,
--7.0 API tables
C_AdventureMap = true,
C_ArtifactUI = true,
C_ChallengeMode = true,
C_ClassTrial = true,
C_LootJournal = true,
C_MapCanvas = true,
C_NamePlate = true,
C_TalkingHead = true,
C_TradeSkillUI = true,
C_Transmog = true,
C_TransmogCollection = true,
--Frames accessed from C
WorldFrame = true,
UIParent = true,
GameTooltip = true,
--7.0 crasher
DAMAGE_TEXT_FONT = true,
}
do
local playername = UnitName("player")
local function parseTOCstring(index, field, func)
local str, enabled = GetAddOnMetadata(index, field), GetAddOnEnableState(playername, index)
if str and enabled then
local i = 2
local nextstr = GetAddOnMetadata(index, field..i)
while nextstr do
str = str.." "..nextstr
nextstr = GetAddOnMetadata(index, field..i)
i = i + 1
end
str:gsub("[%a_][%w_]*", func)
end
end
local imports = setmetatable({}, { __index = function(t, k) t[k] = {} return t[k] end })
for i = 1, GetNumAddOns() do
---A TOC metadata field allowing addons to request that certain globals be kept.
--This is intended for situations where the globals must be accessible to default UI code, such as the use of secure templates.
--This should not be used unless absolutely necessary, as it will pollute the global environment.
--If you need more variables than you can fit in one TOC field, continue your list in X-BlankSlate-Keep2, X-BlankSlate-Keep3, etc.
--@class function
--@name [TOC] X-BlankSlate-Keep
--@param ... List of global variable names. May be separated by any characters which cannot be part of a Lua identifier (e.g. commas or whitespace).
parseTOCstring(i, "X-BlankSlate-Keep", function(var) keepers[var] = true end)
---A TOC metadata field allowing addons to request a copy of a default UI global to be held by BlankSlate.
--This is intended for situations where an addon makes use of default UI data such as localized strings or texture paths that are not available from C API.
--The data will not remain in the global environment (for that, use X-BlankSlate-Keep) and will not be accessible to other addons unless they request it themselves.
--If you need more variables than you can fit in one TOC field, continue your list in X-BlankSlate-Import2, X-BlankSlate-Import3, etc.
--@class function
--@name [TOC] X-BlankSlate-Import
--@param ... List of global variable names. May be separated by any characters which cannot be part of a Lua identifier (e.g. commas or whitespace).
parseTOCstring(i, "X-BlankSlate-Import", function(var) imports[GetAddOnInfo(i)][var] = _G[var] end)
end
---Retrieves imported globals held by BlankSlate.
--@param addon Name of the addon requesting the globals.
--@param ... Names of globals to retrieve.
--@return The requested globals.
function BlankSlate.GetImports(addon, ...)
if select('#', ...) == 1 then
return imports[addon][(...)]
end
local ret = {}
for i = 1, select('#', ...) do
ret[i] = imports[addon][select(i, ...)]
end
return unpack(ret)
end
end
doneframes = {}
for f in function(_, f) return EnumerateFrames(f) end do
if not doneframes[f] and not keepers[f:GetName()] then
FrameNukeAll(f)
end
end
doneframes = nil
FrameWipe(WorldFrame)
FrameWipe(UIParent)
FrameWipe(GameTooltip)
--restore basic tooltip functionality
GameTooltip:SetScript("OnTooltipSetDefaultAnchor", function(self) self:SetOwner(UIParent, "ANCHOR_CURSOR") end)
local function isCfunc(f) return (type(f) == "function" and not pcall(setfenv, f, getfenv(f))) end
local curkey
for tmp in next, _G, curkey do
if keepers[tmp] or isCfunc(_G[tmp]) then
curkey = tmp
else
_G[tmp] = nil
end
end