This repository was archived by the owner on Nov 16, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.lua
More file actions
68 lines (57 loc) · 2.24 KB
/
Copy pathtimer.lua
File metadata and controls
68 lines (57 loc) · 2.24 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
timer = setmetatable
(
{
ñïèñîê = {},
},
{
__index = function(self, key)
if key == "process" then
return function()
if #self.ñïèñîê < 1 then return end
for k, v in ipairs(self.ñïèñîê) do
if v.ôóíêöèÿ_âî_âðåìÿ then v.ôóíêöèÿ_âî_âðåìÿ(self, k) end
if (os.clock() - v.êëîê > v.çàäåðæêà) then
if v.ôóíêöèÿ then v.ôóíêöèÿ(self) end
print(v.íàçâàíèå, "ÈÑÒ¨Ê", os.clock() - v.êëîê)
table.remove(self.ñïèñîê, k); break
end
end
end
elseif key == "exist" then
return function(n)
if #self.ñïèñîê < 1 then return false end
for k, v in ipairs(self.ñïèñîê) do
if v.íàçâàíèå == n then return os.clock() - v.êëîê, v.çàäåðæêà end
end
return false
end
elseif key == "refresh" then
return function(self, t)
local index, del, full = self.exist(t)
self.ñïèñîê[index] = shab
return false
end
elseif key == "remove" then
return function(t)
local index, del, full = self.exist(t)
table.remove(self.ñïèñîê, index)
return false
end
end
end,
__call = function(self, íàçâàíèå, çàäåðæêà, ôóíêöèÿ, ôóíêöèÿ_âî_âðåìÿ)
local shab = { çàäåðæêà = çàäåðæêà, ôóíêöèÿ = ôóíêöèÿ, êëîê = os.clock(),
íàçâàíèå = íàçâàíèå, ôóíêöèÿ_âî_âðåìÿ = ôóíêöèÿ_âî_âðåìÿ }
local index, del, full = self.exist(íàçâàíèå)
--print("òàéìåð ", íàçâàíèå, encodeJson(shab))
if index then
print("òàéìåð ïåðåçàïèñü", íàçâàíèå, encodeJson(shab))
self.ñïèñîê[index] = shab
return
end
print("òàéìåð óñòàíîâëåí", íàçâàíèå, encodeJson(shab))
self.ñïèñîê[#self.ñïèñîê + 1] = shab
return
end
}
)