-
Notifications
You must be signed in to change notification settings - Fork 199
/
repeat.lua
53 lines (43 loc) · 902 Bytes
/
repeat.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
-- repeatedly call a lua script
-- author expwnent
-- vaguely based on a script by Putnam
local repeatUtil = require 'repeat-util'
local utils = require 'utils'
local validArgs = utils.invert({
'help',
'cancel',
'name',
'time',
'timeUnits',
'command',
'list'
})
local args = utils.processArgs({...}, validArgs)
if args.help then
print(usage)
return
end
if args.cancel then
repeatUtil.cancel(args.cancel)
if args.name then
repeatUtil.cancel(args.name)
end
elseif args.command then
local time = tonumber(args.time)
if not args.name then
args.name = args.command[1]
end
if not args.timeUnits then
args.timeUnits = 'ticks'
end
local callCommand = function()
dfhack.run_command(table.unpack(args.command))
end
repeatUtil.scheduleEvery(args.name,time,args.timeUnits,callCommand)
end
if args.list then
for k in pairs(repeatUtil.repeating) do
print(k)
end
return
end