-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathutils.lua
More file actions
66 lines (58 loc) · 1.38 KB
/
Copy pathutils.lua
File metadata and controls
66 lines (58 loc) · 1.38 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
return {
-- Helper function to check if value passed by parameter is a table
-- @obj {table}
-- @returns {boolean}
is_table = function(obj)
return type(obj) == 'table'
end,
-- Raises error if @param is not an array
-- @obj {table}
-- @param {table}
-- @method {string}
-- @returns {void}
raises_error = function(obj, param, method)
assert(obj.is_array(param), string.format('%s expects an array', method))
end,
-- Returns lowest value between two values
-- @a {number}
-- @b {number}
-- @returns number
lowest_value = function(a, b)
return a < b and a or b
end,
-- Makes multiple inserts in a table (array-like)
-- @obj {table}
-- @values {table}
-- @returns {void}
multiple_inserts = function(obj, values)
for i=1, #values do
local value = values[i]
table.insert(obj, value)
end
end,
-- Convert array to hash table
-- @obj {table}
-- @returns {table}
convert_to_hash = function(obj)
local output = {}
for i=1, #obj do
local value = obj[i]
output[value] = true
end
return output
end,
-- Loop through table and print all values
-- @obj {table}
-- @returns {nil}
print_items = function(obj)
for i=1, #obj do
print(obj[i])
end
end,
-- Checks wether value is nil
-- @obj {any}
-- @returns {boolean}
is_nil = function(value)
return value == nil
end
}