Skip to content

Commit 2d66534

Browse files
committed
Improve lua module parsing
1 parent 277816e commit 2d66534

29 files changed

+578
-518
lines changed

dist/library/hack/3rdparty/alt_getopt.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ function altGetopt.get_ordered_opts(args, sh_opts, long_opts) end
88

99
function altGetopt.get_opts(args, sh_opts, long_opts) end
1010

11-
return altGetopt
11+
return altGetopt

dist/library/hack/argparse.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ function argparse.coords(arg, arg_name, skip_validation) end
2020

2121
function argparse.boolean(arg, arg_name) end
2222

23-
return argparse
23+
return argparse

dist/library/hack/binpatch.lua

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,22 @@
22
---@meta
33

44
---@class binpatch
5+
---@field BinaryPatch BinaryPatch
56
local binpatch
67

78
function binpatch.load_dif_file(name) end
89

9-
function binpatch.BinaryPatch:status() end
10+
---@class BinaryPatch
11+
local BinaryPatch = {}
1012

11-
function binpatch.BinaryPatch:isApplied() end
13+
function BinaryPatch:status() end
1214

13-
function binpatch.BinaryPatch:apply() end
15+
function BinaryPatch:isApplied() end
1416

15-
function binpatch.BinaryPatch:isRemoved() end
17+
function BinaryPatch:apply() end
1618

17-
function binpatch.BinaryPatch:remove() end
19+
function BinaryPatch:isRemoved() end
1820

19-
return binpatch
21+
function BinaryPatch:remove() end
22+
23+
return binpatch

dist/library/hack/class.lua

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,4 @@ function class.defclass(class,parent) end
88

99
function class.mkinstance(class,table) end
1010

11-
function class.class_obj:__newindex(name,val) end
12-
13-
function class.attrs_meta:__call(attrs) end
14-
15-
function class.class_obj:__call(init_table) end
16-
17-
function class.common_methods:callback(method, ...) end
18-
19-
function class.common_methods:cb_getfield(field) end
20-
21-
function class.common_methods:cb_setfield(field) end
22-
23-
function class.common_methods:assign(data) end
24-
25-
function class.common_methods:invoke_before(method, ...) end
26-
27-
function class.common_methods:invoke_after(method, ...) end
28-
29-
return class
11+
return class

dist/library/hack/custom-raw-tokens.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ local customRawTokens
66

77
function customRawTokens.getToken(from, b, c) end
88

9-
return customRawTokens
9+
return customRawTokens

dist/library/hack/dfhack.lua

Lines changed: 24 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,16 @@ COLOR_DARKGRAY = COLOR_DARKGREY
5151

5252
-- Events
5353

54-
55-
SC_WORLD_LOADED = 0
56-
SC_WORLD_UNLOADED = 1
57-
SC_MAP_LOADED = 2
58-
SC_MAP_UNLOADED = 3
59-
SC_VIEWSCREEN_CHANGED = 4
60-
SC_CORE_INITIALIZED = 5
61-
SC_PAUSED = 7
62-
SC_UNPAUSED = 8
63-
54+
if dfhack.is_core_context then
55+
SC_WORLD_LOADED = 0
56+
SC_WORLD_UNLOADED = 1
57+
SC_MAP_LOADED = 2
58+
SC_MAP_UNLOADED = 3
59+
SC_VIEWSCREEN_CHANGED = 4
60+
SC_CORE_INITIALIZED = 5
61+
SC_PAUSED = 7
62+
SC_UNPAUSED = 8
63+
end
6464

6565
-- User-changeable options
6666

@@ -105,7 +105,7 @@ function dfhack.with_finalize(cleanup_fn,fn,...) end
105105
function dfhack.with_onerror(cleanup_fn,fn,...) end
106106

107107
---@param obj DFObject
108-
local function call_delete(obj) end
108+
109109

110110
---@generic T
111111
---@param obj DFObject
@@ -118,7 +118,7 @@ dfhack.exception.__index = dfhack.exception
118118

119119
-- Module loading
120120

121-
local function find_required_module_arg() end
121+
122122

123123
---@nodiscard
124124
---@param module string
@@ -153,17 +153,17 @@ NEWLINE = "\n"
153153
COMMA = ","
154154
PERIOD = "."
155155

156-
local function _wrap_iterator(next_fn, ...) end
156+
157157

158158
function safe_pairs(t, iterator_fn) end
159159

160160
-- calls elem_cb(k, v) for each element of the table
161161
-- returns true if we iterated successfully, false if not
162162
-- this differs from safe_pairs() above in that it only calls pcall() once per
163163
-- full iteration and it returns whether iteration succeeded or failed.
164-
local function safe_iterate(table, iterator_fn, elem_cb) end
165164

166-
local function print_element(k, v) end
165+
166+
167167

168168
---@param table table
169169
function printall(table) end
@@ -173,7 +173,7 @@ function printall_ipairs(table) end
173173

174174
local do_print_recurse
175175

176-
local function print_string(printfn, v, seen, indent) end
176+
177177

178178
local fill_chars = {
179179
__index = function(table, key, value)
@@ -185,13 +185,13 @@ local fill_chars = {
185185

186186
setmetatable(fill_chars, fill_chars)
187187

188-
local function print_fields(value, seen, indent, prefix) end
188+
189189

190190
-- This should be same as print_array but userdata doesn't compare equal even if
191191
-- they hold same pointer.
192-
local function print_userdata(printfn, value, seen, indent) end
193192

194-
local function print_array(printfn, value, seen, indent) end
193+
194+
195195

196196
local recurse_type_map = {
197197
number = print_string,
@@ -399,12 +399,12 @@ function dfhack.world.getCurrentSite() end
399399
---@param key string
400400
---@param default? any
401401
---@return any
402-
local function persistent_getData(which, key, default) end
402+
403403

404404
---@param which string
405405
---@param key string
406406
---@param data any
407-
local function persistent_saveData(which, key, data) end
407+
408408

409409
---@nodiscard
410410
---@param key string
@@ -484,7 +484,7 @@ function dfhack.current_script_name() end
484484

485485
function dfhack.script_help(script_name, extension) end
486486

487-
local function _run_command(args, use_console) end
487+
488488

489489
function dfhack.run_command_silent(...) end
490490

@@ -494,57 +494,8 @@ function dfhack.run_command(...) end
494494

495495
function dfhack.getSavePath() end
496496

497-
498-
local function loadInitFile(path, name)
499-
local env = setmetatable({ SAVE_PATH = path }, { __index = base_env })
500-
local f,perr = loadfile(name, 't', env)
501-
if f == nil then
502-
if dfhack.filesystem.exists(name) then
503-
dfhack.printerr(perr)
504-
end
505-
elseif safecall(f) then
506-
if not internal.save_init then
507-
internal.save_init = {}
508-
end
509-
table.insert(internal.save_init, env)
510-
end
511-
end
512-
513-
dfhack.onStateChange.DFHACK_PER_SAVE = function(op)
514-
if op == SC_WORLD_LOADED or op == SC_WORLD_UNLOADED then
515-
if internal.save_init then
516-
for k,v in ipairs(internal.save_init) do
517-
if v.onUnload then
518-
safecall(v.onUnload)
519-
end
520-
end
521-
internal.save_init = nil
522-
end
523-
524-
local path = dfhack.getSavePath()
525-
526-
if path and op == SC_WORLD_LOADED then
527-
loadInitFile(path, path..'/init.lua')
528-
529-
local dirlist = dfhack.internal.getDir(path..'/init.d/')
530-
if dirlist then
531-
table.sort(dirlist)
532-
for i,name in ipairs(dirlist) do
533-
if string.match(name,'%.lua$') then
534-
loadInitFile(path, path..'/init.d/'..name)
535-
end
536-
end
537-
end
538-
end
539-
elseif internal.save_init then
540-
for k,v in ipairs(internal.save_init) do
541-
if v.onStateChange then
542-
safecall(v.onStateChange, op)
543-
end
544-
end
545-
end
546-
end
547-
497+
if dfhack.is_core_context then
498+
548499

549500
-- Feed the table back to the require() mechanism.
550501
return dfhack

dist/library/hack/dfhack/buildings.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -358,11 +358,11 @@ local siegeengine_input = {
358358
}
359359
--[[ Functions for lookup in tables. ]]
360360

361-
local function get_custom_inputs(custom) end
362361

363-
local function get_inputs_by_type(type,subtype,custom) end
364362

365-
local function augment_input(input, argtable) end
363+
364+
365+
366366

367367
function buildings.getFiltersByType(argtable,type,subtype,custom) end
368368

dist/library/hack/dfhack/workshops.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ local workshops
66

77
function workshops.getJobs(buildingId,workshopId,customId) end
88

9-
return workshops
9+
return workshops

dist/library/hack/dumper.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ local dumper
66

77
function dumper.DataDumper(value, varname, fastmode, ident, indent_step) end
88

9-
return dumper
9+
return dumper

0 commit comments

Comments
 (0)