-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLimitedTooltip.lua
More file actions
63 lines (58 loc) · 1.56 KB
/
LimitedTooltip.lua
File metadata and controls
63 lines (58 loc) · 1.56 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
---@class ns
local ns = select(2, ...)
local whitelist = {
AddDoubleLine = true,
AddLine = true,
AddSpellByID = true,
AddTexture = true,
AdvanceSecondaryCompareItem = true,
ResetSecondaryCompareItem = true,
AppendText = true,
SetText = true,
}
local frame = CreateFrame("Frame")
local allowedFunctionsCache
local function getAllowedFunctions()
if not allowedFunctionsCache then
local disallowedFunctions = {}
for key in next, getmetatable(frame).__index do
disallowedFunctions[key] = true
end
local allowedFunctions = {}
for key in next, whitelist do
allowedFunctions[key] = true
end
-- Retail has set functions on the table itself as of 10.0.2, and classic still has them in the metatable
local functionTable = WOW_PROJECT_ID == WOW_PROJECT_MAINLINE and GameTooltip or getmetatable(GameTooltip).__index
for key, value in next, functionTable do
if type(key) == "string" and type(value) == "function" and not disallowedFunctions[key] then
if key:find("^Set[A-Z]") then
allowedFunctions[key] = true
end
end
end
allowedFunctionsCache = allowedFunctions
end
return allowedFunctionsCache
end
---@param tooltip GameTooltip
local function Limit(tooltip)
local allowedFunctions = getAllowedFunctions()
return setmetatable({}, {
__index = function(_, key)
if allowedFunctions[key] then
return function(_, ...)
tooltip[key](tooltip, ...)
end
end
end,
__newindex = function()
error("LimitedTooltip is read only.")
end,
})
end
local export = { Limit = Limit }
if ns then
ns.LimitedTooltip = export
end
return export