Repository navigation
Expand file tree
/
Copy pathinit.lua
More file actions
73 lines (60 loc) · 2.03 KB
/
Copy pathinit.lua
File metadata and controls
73 lines (60 loc) · 2.03 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
local addonName, ns = ...
_G.Roth_UI = ns -- make global so other files see the same object
PlayerFrame:UnregisterAllEvents()
PlayerFrame:Hide()
-- all your init stuff
local LSM = LibStub("LibSharedMedia-3.0")
local mediaCallbacks = {}
local initCallbacks = {}
local configLoaded = false
LSM.RegisterCallback(ns, "LibSharedMedia_Registered", function(name, mediaType, key)
if configLoaded then
for _, callback in pairs(mediaCallbacks) do
callback(name, mediaType, key)
end
end
end)
function ns.RegisterInit(nameOrFunc, maybeFunc)
local name, func
if type(nameOrFunc) == "function" then
func = nameOrFunc
local info = debug.getinfo(func, "Sl") -- get definition site
local src = (type(info.short_src) == "string" and info.short_src) or "?"
local line = tonumber(info.linedefined) or 0
name = ("%s:%d"):format(src:match("AddOns/.+") or src, line)
else
name = tostring(nameOrFunc) -- force string in case someone passed a table
func = maybeFunc
end
local wrapped = function()
local ok, err = xpcall(func, debugstack)
if not ok then
error(("Init callback failed:\n%s"):format(err))
end
end
table.insert(initCallbacks, { name = name, func = wrapped })
end
function ns:Init()
local errors = {}
for _, cb in ipairs(initCallbacks) do
local ok, err = xpcall(cb.func, debugstack)
if not ok then
table.insert(errors, ("Init callback failed:\n%s"):format( err))
end
end
-- After running everything, dump errors (if any) through Blizzard’s handler
if #errors > 0 then
for _, msg in ipairs(errors) do
geterrorhandler()(msg)
end
end
wipe(initCallbacks)
end
function Roth_UI:CheckClientVersion(version)
if WOW_PROJECT_ID ~= version then return false
else return true
end
end
function ns:ListenForMediaChange(callback)
table.insert(mediaCallbacks, callback)
end