Skip to content

Commit 69500d4

Browse files
committed
More luacheck-related fixes.
1 parent 6b78bb5 commit 69500d4

39 files changed

+213
-204
lines changed

caravan.lua

+29-21
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,21 @@ INTERESTING_FLAGS = {
3131
seized = 'Goods seized',
3232
offended = 'Offended'
3333
}
34-
caravans = df.global.ui.caravans
34+
local caravans = df.global.ui.caravans
3535

36-
function caravans_from_ids(ids)
36+
local function caravans_from_ids(ids)
3737
if not ids or #ids == 0 then
38-
return pairs(caravans)
38+
return caravans
3939
end
40-
local i = 0
41-
return function()
42-
i = i + 1
43-
local id = tonumber(ids[i])
40+
41+
local c = {} --as:df.caravan_state[]
42+
for _,id in ipairs(ids) do
43+
local id = tonumber(id)
4444
if id then
45-
return id, caravans[id]
45+
c[id] = caravans[id]
4646
end
47-
return nil
4847
end
48+
return c
4949
end
5050

5151
function bring_back(car)
@@ -54,9 +54,7 @@ function bring_back(car)
5454
end
5555
end
5656

57-
commands = {}
58-
59-
function commands.list()
57+
local function list()
6058
for id, car in pairs(caravans) do
6159
print(dfhack.df2console(('%d: %s caravan from %s'):format(
6260
id,
@@ -73,32 +71,42 @@ function commands.list()
7371
end
7472
end
7573

76-
function commands.extend(days, ...)
74+
local function extend(days, ...)
7775
days = tonumber(days or 7) or qerror('invalid number of days: ' .. days)
78-
for id, car in caravans_from_ids{...} do
76+
for id, car in pairs(caravans_from_ids{...}) do
7977
car.time_remaining = car.time_remaining + (days * 120)
8078
bring_back(car)
8179
end
8280
end
8381

84-
function commands.happy(...)
85-
for id, car in caravans_from_ids{...} do
82+
local function happy(...)
83+
for id, car in pairs(caravans_from_ids{...}) do
8684
-- all flags default to false
8785
car.flags.whole = 0
8886
bring_back(car)
8987
end
9088
end
9189

92-
function commands.leave(...)
93-
for id, car in caravans_from_ids{...} do
90+
local function leave(...)
91+
for id, car in pairs(caravans_from_ids{...}) do
9492
car.trade_state = df.caravan_state.T_trade_state.Leaving
9593
end
9694
end
9795

9896
function main(...)
99-
args = {...}
100-
command = table.remove(args, 1)
101-
commands[command](table.unpack(args))
97+
local args = {...}
98+
local command = table.remove(args, 1)
99+
if command == "list" then
100+
list(table.unpack(args))
101+
elseif command == "extend" then
102+
extend(table.unpack(args))
103+
elseif command == "happy" then
104+
happy(table.unpack(args))
105+
elseif command == "leave" then
106+
leave(table.unpack(args))
107+
else
108+
qerror("No such command: "..command)
109+
end
102110
end
103111

104112
if not dfhack_flags.module then

colonies.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ and ``colonies convert TERMITE`` ends your beekeeping industry.
2121
]====]
2222

2323
function findVermin(target_verm)
24-
for k,v in pairs(df.global.world.raws.creatures.all) do
24+
for k,v in ipairs(df.global.world.raws.creatures.all) do
2525
if v.creature_id == target_verm then
2626
return k
2727
end
@@ -31,7 +31,7 @@ end
3131

3232
function list_colonies()
3333
for idx, col in pairs(df.global.world.vermin.colonies) do
34-
race = df.global.world.raws.creatures.all[col.race].creature_id
34+
local race = df.global.world.raws.creatures.all[col.race].creature_id
3535
print(race..' at '..col.pos.x..', '..col.pos.y..', '..col.pos.z)
3636
end
3737
end

devel/annc-monitor.lua

+11-14
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@ Displays announcements and reports in the console.
1515

1616
VERSION = '0.2'
1717

18-
eventful = require 'plugins.eventful'
18+
local eventful = require 'plugins.eventful'
1919

20-
if enabled == nil then
21-
enabled = false
22-
end
20+
enabled = enabled or false
2321

2422
function usage()
2523
print [[
@@ -35,15 +33,7 @@ function log(s, color)
3533
dfhack.color(COLOR_RESET)
3634
end
3735

38-
function annc_handler(id)
39-
if enabled and dfhack.isWorldLoaded() then
40-
local annc = df.report.find(id)
41-
local color = annc.color + (annc.bright and 8 or 0)
42-
log(annc.text, color)
43-
end
44-
end
45-
46-
args = {...}
36+
local args = {...}
4737
if dfhack_flags and dfhack_flags.enable then
4838
table.insert(args, dfhack_flags.enable_state and 'enable' or 'disable')
4939
end
@@ -60,4 +50,11 @@ else
6050
end
6151

6252
eventful.enableEvent(eventful.eventType.REPORT, 1)
63-
eventful.onReport.annc_monitor = annc_handler
53+
function eventful.onReport.annc_monitor(id)
54+
if enabled and dfhack.isWorldLoaded() then
55+
local annc = df.report.find(id)
56+
local color = annc.color + (annc.bright and 8 or 0)
57+
log(annc.text, color)
58+
end
59+
end
60+

devel/check-release.lua

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ devel/check-release
55
Basic checks for release readiness
66
]====]
77

8-
ok = true
8+
local ok = true
99
function err(s)
1010
dfhack.printerr(s)
1111
ok = false
@@ -16,9 +16,9 @@ function warn(s)
1616
dfhack.color(nil)
1717
end
1818

19-
dfhack_ver = dfhack.getDFHackVersion()
20-
git_desc = dfhack.getGitDescription()
21-
git_commit = dfhack.getGitCommit()
19+
local dfhack_ver = dfhack.getDFHackVersion()
20+
local git_desc = dfhack.getGitDescription()
21+
local git_commit = dfhack.getGitCommit()
2222
if not dfhack.isRelease() then
2323
err('This build is not tagged as a release')
2424
print[[
@@ -27,7 +27,7 @@ Try running `git fetch origin --tags` in the DFHack source tree.
2727
]]
2828
end
2929

30-
expected_git_desc = ('%s-0-g%s'):format(dfhack_ver, git_commit:sub(1, 8))
30+
local expected_git_desc = ('%s-0-g%s'):format(dfhack_ver, git_commit:sub(1, 8))
3131
if git_desc:sub(1, #expected_git_desc) ~= expected_git_desc then
3232
err(([[Bad git description:
3333
Expected %s, got %s]]):format(expected_git_desc, git_desc))

devel/clear-script-env.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ devel/clear-script-env
66
Clears the environment of the specified lua script(s).
77
88
]====]
9-
args = {...}
9+
local args = {...}
1010
if #args < 1 then qerror("script name(s) required") end
1111
for _, name in pairs(args) do
1212
local file = dfhack.findScript(name)
1313
if file then
1414
local script = dfhack.internal.scripts[file]
15-
if script then
15+
if script then --luacheck: skip
1616
local env = script.env
1717
while next(env) do
1818
env[next(env)] = nil

devel/click-monitor.lua

+7-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Usage: ``devel/click-monitor start|stop``
1313

1414
VERSION = '0.2'
1515

16-
if active == nil then active = false end
16+
active = active or false
1717

1818
function usage()
1919
print [[
@@ -27,6 +27,8 @@ function set_timeout()
2727
dfhack.timeout(1, 'frames', check_click)
2828
end
2929

30+
last_msg = last_msg or ''
31+
3032
function log(s, color)
3133
-- prevent duplicate output
3234
if s ~= last_msg then
@@ -36,12 +38,14 @@ function log(s, color)
3638
end
3739
end
3840

41+
--luacheck: in=none
3942
function check_click()
4043
local s = ''
4144
local color = COLOR_RESET
4245
for _, attr in pairs({'mouse_lbut', 'mouse_rbut', 'mouse_lbut_down',
4346
'mouse_rbut_down', 'mouse_lbut_lift', 'mouse_rbut_lift'}) do
44-
if df.global.enabler[attr] ~= 0 then
47+
local enabler = df.global.enabler --as:number[]
48+
if enabler[attr] ~= 0 then
4549
s = s .. '[' .. attr:sub(7) .. '] '
4650
end
4751
end
@@ -58,7 +62,7 @@ function check_click()
5862
if active then set_timeout() end
5963
end
6064

61-
args = {...}
65+
local args = {...}
6266
if dfhack_flags and dfhack_flags.enable then
6367
table.insert(args, dfhack_flags.enable_state and 'enable' or 'disable')
6468
end

devel/cmptiles.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ local nmat1,nmat2=...
1313
local mat1 = df.tiletype_material[nmat1]
1414
local mat2 = df.tiletype_material[nmat2]
1515

16-
local tmat1 = {}
17-
local tmat2 = {}
16+
local tmat1 = {} --as:bool[]
17+
local tmat2 = {} --as:bool[]
1818

1919
local attrs = df.tiletype.attrs
2020

devel/dump-offsets.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ else
191191
search = {0x12345678, 0x87654321}
192192
end
193193

194-
addrs = {}
194+
local addrs = {}
195195
function save_addr(name, addr)
196196
print(("<global-address name='%s' value='0x%x'/>"):format(name, addr))
197197
if iargs[name] or iargs.all then

devel/export-dt-ini.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ local function address(name,base,field,...)
4545
_,addr = df.sizeof(ms.field_ref(base,field,...))
4646
end
4747
addr = addr - rdelta
48-
elseif base._kind == 'class-type' then
48+
elseif base._kind == 'class-type' then --luacheck: skip
4949
-- field_offset crashes with classes due to vtable problems,
5050
-- so we have to create a real temporary object here.
5151
local obj = df.new(base)
@@ -467,6 +467,7 @@ end
467467

468468
-- Flags
469469
local function write_flags(name,flag_array)
470+
local flag_array = flag_array --as:{1:string,2:'number[]'}[]
470471
out:write('\n')
471472
out:write('['..name..']\n')
472473
out:write('size='..#flag_array..'\n')

devel/find-offsets.lua

+9-6
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ local is_known = dfhack.internal.getAddress
3939

4040
local os_type = dfhack.getOSType()
4141

42-
local force_scan = {}
42+
local force_scan = {} --as:bool[]
4343
for _,v in ipairs({...}) do
4444
force_scan[v] = true
4545
end
@@ -167,10 +167,12 @@ end
167167

168168
local finder_searches = {}
169169
local function exec_finder(finder, names, validators)
170-
if type(names) ~= 'table' then
170+
local names = names --as:string[]
171+
local validators = validators --as:{_type:function,_node:bool}[]
172+
if type(names) ~= 'table' then --luacheck: skip
171173
names = { names }
172174
end
173-
if type(validators) ~= 'table' then
175+
if type(validators) ~= 'table' then --luacheck: skip
174176
validators = { validators }
175177
end
176178
local search = force_scan['all']
@@ -179,7 +181,7 @@ local function exec_finder(finder, names, validators)
179181
table.insert(finder_searches, v)
180182
search = true
181183
elseif validators[k] then
182-
if not validators[k](df.global[v]) then
184+
if not validators[k](df.global[v]) then --luacheck: skip
183185
dfhack.printerr('Validation failed for '..v..', will try to find again')
184186
table.insert(finder_searches, v)
185187
search = true
@@ -259,7 +261,7 @@ local function dwarfmode_to_top()
259261
return false
260262
end
261263

262-
local screen = screen_dwarfmode()
264+
local screen = screen_dwarfmode() --as:df.viewscreen_dwarfmodest
263265
if not df.isvalid(screen) then
264266
return false
265267
end
@@ -1794,8 +1796,9 @@ local function find_standing_orders(gname, seq, depends)
17941796
end
17951797

17961798
local function exec_finder_so(gname, seq, _depends)
1797-
local depends = {}
1799+
local depends = {} --as:number[]
17981800
for k, v in pairs(_depends or {}) do
1801+
local v = v --as:number
17991802
if k:find('standing_orders_') ~= 1 then
18001803
k = 'standing_orders_' .. k
18011804
end

0 commit comments

Comments
 (0)