-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSPD.lua
91 lines (77 loc) · 2.1 KB
/
SPD.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
-- NOT TESTED, WIP
-- Simple postdate data
local SPD = {}
local tinsert = table.insert
local assert = assert
local type = type
SPD.containers = {}
local containers = SPD.containers
local performer_name
---@param func function
---@param container_name string
---@param func_name string # Use it for identification
---@param position? number
---@return boolean # is added?
SPD.add_function = function(container_name, func, func_name, position)
local container = containers[container_name]
if container == nil then return false end
assert(type(func_name) == "string", "The func_name isn't string")
if position then
tinsert(container.functions, position, {func, func_name})
else
local functions = container.functions
functions[#functions+1] = {func, func_name}
end
return true
end
---@param container_name string
---@param element any
---@return boolean # is added?
SPD.add_element = function(container_name, element)
local container = containers[container_name]
if container == nil then return false end
local data = container.data
data[#data+1] = element
return true
end
---@param name string
---@return table # container
SPD.create_container = function(name)
containers[name] = containers[name] or {}
local container = containers[name]
container.data = container.data or {}
container.functions = container.functions or {}
return container
end
---@param name string
SPD.get_container = function(name)
return containers[name]
end
---@param mod_name string
SPD.assign_performer = function(mod_name)
performer_name = mod_name
end
---@return string?
SPD.get_assigned_performer = function()
return performer_name
end
---@param mod_name string
---@return boolean # is performed?
SPD.process = function(mod_name)
if performer_name ~= mod_name then return false end
for name, container in pairs(containers) do
local data = container.data
local functions = container.functions
for i=1, #functions do
local func = functions[i][1]
for j=#data, 1, -1 do
func(data[j], container, name, j)
end
end
end
performer_name = nil
SPD.containers = {}
containers = SPD.containers
return true
end
return SPD