-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathargs.lua
60 lines (50 loc) · 1.21 KB
/
args.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
Args = {
debug = {
---@diagnostic disable-next-line: unused-local
callback = function(pos)
IsDebug = true
love.window.setTitle(love.window.getTitle() .. " (DEBUG)")
end,
},
["debug-ui"] = {
---@diagnostic disable-next-line: unused-local
callback = function(pos)
IsDebug = true
love.window.setTitle(love.window.getTitle() .. " (DEBUG)")
---@diagnostic disable-next-line: lowercase-global
vudu = require("lib.vudu.vudu")
vudu:initialize()
vudu:initializeDefaultHotkeys()
end,
},
seed = {
callback = function(pos)
if arg[pos + 1] == nil or not arg[pos + 1]:find("%d+") then
error("No seed was provided or invalid seed!")
end
-- arg[pos + 1] WILL be numeric 100%
---@diagnostic disable-next-line: param-type-mismatch
love.math.setRandomSeed(tonumber(arg[pos + 1]))
end,
},
}
local function asArg(a)
if string.sub(a, 1, 2) == "--" then
return string.sub(a, 3, #a), true
elseif string.sub(a, 1, 1) == "-" then
return string.sub(a, 2, #a), true
end
return a, false
end
function ParseArgs()
for k, v in ipairs(arg) do
local a, opt = asArg(v)
if not opt then
goto continue
end
if Args[a] ~= nil then
Args[a].callback(k)
end
::continue::
end
end