-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.lua
43 lines (37 loc) · 871 Bytes
/
utils.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
--
-- Various util functions
--
local This = {}
-- Sugar for binding functions
function This:bind(reference, functionName)
return function()
reference[functionName](reference)
end
end
-- Sugar for adding to tables
function This:addToTable(target, inputTable)
for _, value in pairs(inputTable) do
table.insert(target, value)
end
end
-- Sugar for splitting a string into a table
function This:split(s, delimiter)
local result = {}
for match in (s .. delimiter):gmatch("(.-)" .. delimiter) do
if (match ~= "") then
table.insert(result, match)
end
end
return result
end
-- Sugar for reversing a table
function This:reverse(table)
local n = #table
local i = 1
while i < n do
table[i], table[n] = table[n], table[i]
i = i + 1
n = n - 1
end
end
return This