-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipe.lua
96 lines (74 loc) · 1.68 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
local _, ns = ...
local SyLevel = ns.SyLevel
local pipesTable = {}
local numPipes = 0
local argcheck = SyLevel.argcheck
function SyLevel: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 m, t = next(pipesTable, n)
if (t) then
return m, t.isActive, t.name, t.desc
end
end
function SyLevel.IteratePipes()
return iter, nil, nil
end
end
function SyLevel:EnablePipe(pipe)
argcheck(pipe, 2, "string")
local ref = pipesTable[pipe]
if (ref and not ref.isActive) then
ref.enable(self)
ref.isActive = true
SyLevelDB.EnabledPipes[pipe] = true
return true
end
end
function SyLevel: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 = false
SyLevelDB.EnabledPipes[pipe] = false
return true
end
end
function SyLevel:IsPipeEnabled(pipe)
argcheck(pipe, 2, "string")
return pipesTable[pipe].isActive
end
function SyLevel:UpdatePipe(pipe)
argcheck(pipe, 2, "string")
local ref = pipesTable[pipe]
if (ref) then
ref.update(self)
return true
end
end
function SyLevel:GetNumPipes()
return numPipes
end
ns.pipesTable = pipesTable