LiquidProxy Lua Edition
1One = {
2 minute = 60,
3 hour = 60 * 60
4}
5function UnixEpoch()
6---@diagnostic disable-next-line: param-type-mismatch
7 return os.time(os.date("!*t"))
8end
9
10local function table_patch(table, patches)
11 for k, v in pairs(patches) do
12 if type(table[k]) == "table" then
13 if (not next(table)) or #table ~= 0 then
14 table[k] = v
15 else
16 table_patch(table[k], patches[k])
17 end
18 else
19 table[k] = v
20 end
21 end
22 return table
23end
24
25table.patch = table_patch
26
27function table.v2k(t)
28 local new = {}
29 for k, v in pairs(t) do
30 new[v] = k
31 end
32 return new
33end
34
35function table.has(t, v)
36 for _, w in pairs(t) do
37 if v == w then
38 return true
39 end
40 end
41end
42
43function table.keyof(t, v)
44 for k, w in pairs(t) do
45 if v == w then
46 return k
47 end
48 end
49 return nil
50end
51
52function table.indexof(t, v)
53 for i, _, w in ipairs(t) do
54 if v == w then
55 return i
56 end
57 end
58 return nil
59end
60
61function table.keylist(t)
62 local u = {}
63 for k in pairs(t) do
64 table.insert(u, k)
65 end
66 return u
67end
68
69-- True if one value from left table exists as a value in right table
70function table.hasleftinright(t,u)
71 for _, v in pairs(t) do
72 for _, w in pairs(u) do
73 if v == w then
74 return true
75 end
76 end
77 end
78 return false
79end
80
81-- Properly clones table in first argument, and returns it. Always deep.
82function table.clone(tbl)
83 local t = {}
84 for k, v in pairs(tbl) do
85 local v = v
86 if type(v) == "table" then
87 v = table.clone(v)
88 end
89 t[k] = v
90 end
91 return t
92end