My new system(which is immume to frame.Fire):
lua Code:
local version = 1.0
local metatables, registered = {}, {}
local noop = function() end
if LibCoreAPI then if LibCoreAPI.version<version then registered=LibCoreAPI.RegisteredAddons else return end end
for key, val in pairs(_G) do
if type(val)=="table" and val.GetObjectType then
obj = val:GetObjectType()
if not metatables[obj] then
metatables[obj] = getmetatable(val).__index
end
end
end
local function registeraddon()
registered[gsub(debugstack(2), ".*\\(.+)\\.+", "%1")] = true
end
local function destroy(self)
self.Show = noop
self:Hide()
if self.UnregisterAllEvents then
self:UnregisterAllEvents()
end
end
local function fireevent(self, event, ...)
local handler = self:GetScript("OnEvent")
if handler then
handler(self, event, ...)
return true
end
return false
end
local function fire(self, script, ...)
local handler = self:GetScript(script)
if handler then
handler(self, ...)
return true
end
return false
end
local function lock(self)
self.ClearAllPoints = noop
self.SetPoint = noop
self.SetAllPoints = noop
end
local function unlock(self)
self.ClearAllPoints = nil
self.SetPoint = nil
self.SetAllPoints = nil
end
local function setsize(self, w, h)
self:SetWidth(w)
self:SetHeight(h or w)
end
local function getclassbycolor(r, g, b)
r, g, b = floor(r*100+.5)/100, floor(g*100+.5)/100, floor(b*100+.5)/100
for class, color in pairs(RAID_CLASS_COLORS) do
if color.r==r and color.g==g and color.b==b then
return class
end
end
return false
end
local function getsize(self)
return self:GetWidth(), self:GetHeight()
end
local function setclassicon(self, class)
self:SetTexture("Interface\\WorldStateFrame\\Icons-Classes")
if class then
local classcoords = CLASS_BUTTONS[class]
if classcoords then
self:SetTexCoord(unpack(classcoords))
return true
else
self:SetTexCoord(.5, .75, .5, .75)
return false
end
end
return false
end
local function islocked(self)
if self.ClearAllPoints==noop and self.SetPoint==noop and self.SetAllPoints==noop then
return true
end
return false
end
local function isdestroyed(self)
if self.Show==noop and not self:IsShown() then
return true
end
return false
end
local function toggle(self)
if self:IsShown() then
self:Hide()
return false
end
self:Show()
return true
end
local function setshown(self, show)
if show then
self:Show()
else
self:Hide()
end
end
local methods = {
Destroy = destroy,
IsDestroyed = isdestroyed,
SetSize = setsize,
GetSize = getsize,
Lock = lock,
Unlock = unlock,
IsLocked = islocked,
Toggle = toggle,
SetShown = setshown,
FireEvent = fireevent,
Fire = fire,
SetClassIcon = setclassicon,
}
local dependencies = {
Destroy = "Hide",
IsDestroyed = "Hide",
SetSize = "Hide",
GetSize = "Hide",
Lock = "Hide",
Unlock = "Hide",
IsLocked = "Hide",
Toggle = "Hide",
SetShown = "Hide",
FireEvent = "RegisterEvent",
Fire = "GetScript",
SetClassIcon = "SetTexture",
}
local mt = {
__index = function(tab, func)
return registered[gsub(debugstack(2), ".*\\(.+)\\.+", "%1")] and methods[func] or nil
end
}
for key, val in pairs(metatables) do
setmetatable(val, mt)
end
LibCoreAPI = {
GetClassByColor = getclassbycolor,
Metatables = metatables,
RegisteredAddons = registered,
version = version,
}
setmetatable(LibCoreAPI, {
__call = registeraddon,
})
If an addon calls LibCoreAPI() then it get's whitelisted and frame
estroy() will return the correct function. If it's not whitelisted then frame.Fire will return an not found error.