-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathpipe.lua
97 lines (74 loc) · 1.65 KB
/
pipe.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
local _, ns = ...
local oGlow = ns.oGlow
local pipesTable = {}
local numPipes = 0
local argcheck = oGlow.argcheck
function oGlow:RegisterPipe(pipe, enable, disable, update, name, desc)
argcheck(pipe, 2, 'string')
argcheck(enable, 3, 'function')
argcheck(disable, 4, 'function', 'nil')
argcheck(update, 5, 'function')
argcheck(name, 6, 'string', 'nil')
argcheck(desc, 7, 'string', 'nil')
-- Silently fail.
if(pipesTable[pipe]) then
return nil, string.format('Pipe [%s] is already registered.')
else
numPipes = numPipes + 1
pipesTable[pipe] = {
enable = enable;
disable = disable;
name = name;
update = update;
desc = desc;
}
end
return true
end
do
local function iter(_, n)
local n, t = next(pipesTable, n)
if(t) then
return n, t.isActive, t.name, t.desc
end
end
function oGlow.IteratePipes()
return iter, nil, nil
end
end
function oGlow:EnablePipe(pipe)
argcheck(pipe, 2, 'string')
local ref = pipesTable[pipe]
if(ref and not ref.isActive) then
ref.enable(self)
ref.isActive = true
oGlowDB.EnabledPipes[pipe] = true
return true
end
end
function oGlow:DisablePipe(pipe)
argcheck(pipe, 2, 'string')
local ref = pipesTable[pipe]
if(ref and ref.isActive) then
if(ref.disable) then ref.disable(self) end
ref.isActive = nil
oGlowDB.EnabledPipes[pipe] = nil
return true
end
end
function oGlow:IsPipeEnabled(pipe)
argcheck(pipe, 2, 'string')
return pipesTable[pipe].isActive
end
function oGlow:UpdatePipe(pipe)
argcheck(pipe, 2, 'string')
local ref = pipesTable[pipe]
if(ref) then
ref.update(self)
return true
end
end
function oGlow:GetNumPipes()
return numPipes
end
ns.pipesTable = pipesTable