-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.lua
More file actions
70 lines (57 loc) · 1.26 KB
/
helpers.lua
File metadata and controls
70 lines (57 loc) · 1.26 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
68
69
70
local S = core.get_translator(listitems.modname)
local options = {
["-v"] = {name="verbose", description=S("Display descriptions")},
["-s"] = {name="shallow", description=S("Don't search descriptions")},
}
--- Valid list types.
--
-- @table known_types
-- @local
local known_types = {
"items",
"entities",
"nodes",
"ores",
"tools",
}
if core.global_exists("mobs") then
table.insert(known_types, "mobs")
end
--- Checks if value is contained in list.
--
-- @function listContains
-- @local
-- @tparam table tlist List to be iterated.
-- @tparam string v String to search for in list.
-- @treturn boolean ***true*** if string found within list.
function listContains(tlist, v)
for index, value in ipairs(tlist) do
if v == value then
return true
end
end
return false
end
--- Replaces duplicates found in a list.
--
-- @function removeListDuplicates
-- @local
-- @tparam table tlist
-- @treturn table
function removeListDuplicates(tlist)
local cleaned = {}
if tlist ~= nil then
for index, value in ipairs(tlist) do
if not listContains(cleaned, value) then
table.insert(cleaned, value)
end
end
end
return cleaned
end
return {
options = options,
known_types = known_types,
listContains = listContains,
removeListDuplicates = removeListDuplicates,
}