Skip to content

Commit e007982

Browse files
committed
Parse WRAPN functions better
1 parent ee9a446 commit e007982

File tree

8 files changed

+135
-35
lines changed

8 files changed

+135
-35
lines changed

dist/library/modules/buildings.lua

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
---@meta
33

44
---@class dfhack.buildings
5-
---@field containsTile function
65
---@field setSize function
76
---@field getStockpileContents function
87
---@field getCageOccupants function
@@ -30,6 +29,12 @@ function dfhack.buildings.getCorrectSize(center, type, subtype, custom, directio
3029
---@return df.building
3130
function dfhack.buildings.findPenPitAt(coord) end
3231

32+
---@param bld df.building
33+
---@param x integer
34+
---@param y integer
35+
---@return boolean
36+
function dfhack.buildings.containsTile(bld, x, y) end
37+
3338
---@param building df.building
3439
---@param type df.general_ref_type
3540
---@return df.general_ref

dist/library/modules/burrows.lua

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,27 @@
22
---@meta
33

44
---@class dfhack.burrows
5-
---@field isAssignedBlockTile function
6-
---@field setAssignedBlockTile function
75
dfhack.burrows = {}
86

97
---@param pvec { [integer]: df.map_block }
108
---@param burrow df.burrow
119
function dfhack.burrows.listBlocks(pvec, burrow) end
1210

11+
---@param burrow df.burrow
12+
---@param block df.map_block
13+
---@param x integer
14+
---@param y integer
15+
---@return boolean
16+
function dfhack.burrows.isAssignedBlockTile(burrow, block, x, y) end
17+
18+
---@param burrow df.burrow
19+
---@param block df.map_block
20+
---@param x integer
21+
---@param y integer
22+
---@param enable boolean|nil
23+
---@return boolean
24+
function dfhack.burrows.setAssignedBlockTile(burrow, block, x, y, enable) end
25+
1326
---@param name string
1427
---@param ignore_final_plus boolean|nil
1528
---@return df.burrow

dist/library/modules/gui.lua

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

44
---@class dfhack.gui
5-
---@field addCombatReport function
6-
---@field addCombatReportAuto function
75
---@field getCurFocus function
86
---@field getWidgetChildren function
97
dfhack.gui = {}

dist/library/modules/internal.lua

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

44
---@class dfhack.internal
5-
---@field strerror function
6-
---@field md5 function
7-
---@field heapTakeSnapshot function
8-
---@field getHeapState function
9-
---@field isAddressInHeap function
10-
---@field isAddressActiveInHeap function
11-
---@field isAddressUsedAfterFreeInHeap function
12-
---@field getAddressSizeInHeap function
13-
---@field getRootAddressOfHeapObject function
14-
---@field msizeAddress function
155
---@field getPE function
166
---@field getMD5 function
177
---@field getAddress function
@@ -44,3 +34,44 @@
4434
---@field getPerfCounters function
4535
dfhack.internal = {}
4636

37+
---@param n integer
38+
---@return string
39+
function dfhack.internal.strerror(n) end
40+
41+
---@param s string
42+
---@return string
43+
function dfhack.internal.md5(s) end
44+
45+
-- this function only allocates the first time it is called
46+
---@return integer
47+
function dfhack.internal.heapTakeSnapshot() end
48+
49+
---@return integer
50+
function dfhack.internal.getHeapState() end
51+
52+
---@param ptr unknown
53+
---@return boolean
54+
function dfhack.internal.isAddressInHeap(ptr) end
55+
56+
---@param ptr unknown
57+
---@return boolean
58+
function dfhack.internal.isAddressActiveInHeap(ptr) end
59+
60+
---@param ptr unknown
61+
---@return boolean
62+
function dfhack.internal.isAddressUsedAfterFreeInHeap(ptr) end
63+
64+
---@param ptr unknown
65+
---@return integer
66+
function dfhack.internal.getAddressSizeInHeap(ptr) end
67+
68+
-- eg if I have a struct, does any address lie within the struct?
69+
---@param ptr unknown
70+
---@return unknown
71+
function dfhack.internal.getRootAddressOfHeapObject(ptr) end
72+
73+
-- is in the heap/valid
74+
---@param ptr unknown
75+
---@return integer
76+
function dfhack.internal.msizeAddress(ptr) end
77+

dist/library/modules/items.lua

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

44
---@class dfhack.items
5-
---@field moveToGround function
6-
---@field moveToContainer function
7-
---@field moveToInventory function
8-
---@field makeProjectile function
9-
---@field remove function
10-
---@field findType function
11-
---@field findSubtype function
125
dfhack.items = {}
136

147
---@param item df.item
@@ -41,6 +34,40 @@ function dfhack.items.moveToBuilding(item, building, use_mode, force_in_building
4134
---@return boolean
4235
function dfhack.items.createItem(unit, item_type, item_subtype, mat_type, mat_index, growth_print, no_floor) end
4336

37+
---@param item df.item
38+
---@param pos df.coord
39+
---@return boolean
40+
function dfhack.items.moveToGround(item, pos) end
41+
42+
---@param item df.item
43+
---@param container df.item
44+
---@return boolean
45+
function dfhack.items.moveToContainer(item, container) end
46+
47+
---@param item df.item
48+
---@param unit df.unit
49+
---@param mode df.unit_inventory_item::T_mode
50+
---@param body_part integer
51+
---@return boolean
52+
function dfhack.items.moveToInventory(item, unit, mode, body_part) end
53+
54+
---@param item df.item
55+
---@return df.proj_itemst
56+
function dfhack.items.makeProjectile(item) end
57+
58+
---@param item df.item
59+
---@param no_uncat boolean|nil
60+
---@return boolean
61+
function dfhack.items.remove(item, no_uncat) end
62+
63+
---@param token string
64+
---@return number
65+
function dfhack.items.findType(token) end
66+
67+
---@param token string
68+
---@return number
69+
function dfhack.items.findSubtype(token) end
70+
4471
---@param item df.item
4572
---@param type df.general_ref_type
4673
---@return df.general_ref

dist/library/modules/job.lua

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

44
---@class dfhack.job
5-
---@field is_equal function
6-
---@field is_item_equal function
75
dfhack.job = {}
86

97
---@param pvec { [integer]: df.job }
108
---@param id_var integer
119
---@return boolean
1210
function dfhack.job.listNewlyCreated(pvec, id_var) end
1311

12+
---@param job1 df.job
13+
---@param job2 df.job
14+
---@return boolean
15+
function dfhack.job.is_equal(job1, job2) end
16+
17+
---@param job1 df.job_item
18+
---@param job2 df.job_item
19+
---@return boolean
20+
function dfhack.job.is_item_equal(job1, job2) end
21+
1422
---@param job df.job
1523
---@param item df.item
1624
---@param role df.job_item_ref::T_role

dist/library/modules/maps.lua

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

44
---@class dfhack.maps
5-
---@field getBlock function
6-
---@field hasTileAssignment function
7-
---@field getTileAssignment function
8-
---@field setTileAssignment function
9-
---@field resetTileAssignment function
105
---@field getTileFlags function
116
---@field getTileBiomeRgn function
127
---@field getBiomeType function
@@ -52,6 +47,26 @@ function dfhack.maps.getRegionBiome(rgn_pos) end
5247
---@return df.plant
5348
function dfhack.maps.getPlantAtTile(x, y, z) end
5449

50+
---@param bm df.tile_bitmask
51+
---@return boolean
52+
function dfhack.maps.hasTileAssignment(bm) end
53+
54+
---@param bm df.tile_bitmask
55+
---@param x integer
56+
---@param y integer
57+
---@return boolean
58+
function dfhack.maps.getTileAssignment(bm, x, y) end
59+
60+
---@param bm df.tile_bitmask
61+
---@param x integer
62+
---@param y integer
63+
---@param val boolean|nil
64+
function dfhack.maps.setTileAssignment(bm, x, y, val) end
65+
66+
---@param bm df.tile_bitmask
67+
---@param val boolean|nil
68+
function dfhack.maps.resetTileAssignment(bm, val) end
69+
5570
---@param blk df.map_block
5671
---@param flow boolean|nil
5772
---@param temperature boolean|nil

lib/cpp.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def parse_cpp_modules(entry_point)
5858

5959
# Functions with signatures that I currently don't understand well
6060
# enough to parse.
61-
module_declaration&.scan(/(?:WRAP_VERSION_FUNC|WRAPN)\(([^)]+)\)/) do |match|
61+
module_declaration&.scan(/(?:WRAP_VERSION_FUNC)\(([^)]+)\)/) do |match|
6262
function_name = match[0].split(', ')[0]
6363
output << "---@field #{function_name} function\n"
6464
end
@@ -77,12 +77,10 @@ def parse_cpp_modules(entry_point)
7777
signature_name = signature.gsub(/"/, '').strip
7878

7979
cleaned_signature_name = signature_name.gsub(/#{module_name}_/, '')
80-
module_file[/^(?:static\s)?(?:DFHACK_EXPORT\s)?(\S+).*?#{namespace}#{cleaned_signature_name}\s?\(([^)]+)?\)/]
80+
module_file[/^(?:static\s)?(?:DFHACK_EXPORT\s)?(\S+).*?#{namespace}#{cleaned_signature_name}\R?\s*\(([^)]+)?\)/]
8181
next if Regexp.last_match
8282

83-
file[/^(?:static\s)?(?:DFHACK_EXPORT\s)?(\S+).*?#{signature_name}\s?\(([^)]+)?\)/]
84-
next unless Regexp.last_match
85-
83+
file[/^(?:static\s)?(?:DFHACK_EXPORT\s)?(\S+).*?#{signature_name}\R?\s*\(([^)]+)?\)/]
8684
output << "---@field #{function_name} function\n"
8785
end
8886

@@ -98,13 +96,18 @@ def parse_cpp_modules(entry_point)
9896
signature_name = signature.gsub(/"/, '').strip
9997

10098
cleaned_signature_name = signature_name.gsub(/#{module_name}_/, '')
101-
module_file[%r{(//.*\R)?^(?:static\s)?(?:DFHACK_EXPORT\s)?(\S+).*?#{namespace}#{cleaned_signature_name}\s?\(([^)]+)?\)}]
99+
module_file[%r{(//.*\R)?^(?:static\s)?(?:DFHACK_EXPORT\s)?(\S+).*?#{namespace}#{cleaned_signature_name}\R?\s*\(([^)]+)?\)}]
102100
next unless Regexp.last_match
103101

104102
functions << DFHackLuaDefinitions::CPP.parse_function(Regexp.last_match, module_name:, prefix:,
105103
function_name:)
106104
end
107105

106+
module_declaration&.scan(/WRAPN\(\s*(\w+)\s*,\s*(\w+)\s*\)/) do |function_name, signature_name|
107+
file[%r{(//.*\R)?^(?:static\s)?(\S+).*?#{signature_name}\R?\s*\(([^)]+)?\)}]
108+
functions << CPP.parse_function(Regexp.last_match, module_name:, prefix:, function_name:)
109+
end
110+
108111
module_declaration&.scan(/(?:WRAP|WRAPM)\((.+)?\),?/) do |function_name,|
109112
function_name = Regexp.last_match(1) if function_name =~ /,\s?(\S+)/
110113
signature = "#{namespace}#{function_name}"

0 commit comments

Comments
 (0)