Skip to content

Commit df0b520

Browse files
committed
Support top level comments in cpp files
1 parent 6021c46 commit df0b520

File tree

7 files changed

+29
-10
lines changed

7 files changed

+29
-10
lines changed

dist/library/modules/buildings.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ function dfhack.buildings.findCivzonesAt(pvec, pos) end
2525
---@return df.coord2d size
2626
function dfhack.buildings.getCorrectSize(center, type, subtype, custom, direction) end
2727

28+
-- returns building of pen/pit at cursor position (NULL if nothing found)
2829
---@param coord df.coord
2930
---@return df.building
3031
function dfhack.buildings.findPenPitAt(coord) end

dist/library/modules/gui.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ function dfhack.gui.pauseRecenter(x, y, z, pause) end
7070
---@return boolean
7171
function dfhack.gui.revealInDwarfmodeMap(x, y, z, center, highlight) end
7272

73+
-- returns the map coordinates that the mouse cursor is over
7374
---@param allow_out_of_bounds boolean|nil
7475
---@return df.coord
7576
function dfhack.gui.getMousePos(allow_out_of_bounds) end

dist/library/modules/items.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ function dfhack.items.getHolderBuilding(item) end
7373
---@return df.unit
7474
function dfhack.items.getHolderUnit(item) end
7575

76+
-- It's not impossible the functionality of this operation is provided by one of the unmapped item functions.
7677
---@param item df.item
7778
---@return string
7879
function dfhack.items.getBookTitle(item) end
@@ -138,6 +139,7 @@ function dfhack.items.canTradeAnyWithContents(item) end
138139
---@return boolean
139140
function dfhack.items.markForTrade(item, depot) end
140141

142+
-- (i.e., returning true if and only if the item has a "designate for melting" button in game)
141143
---@param item df.item
142144
---@param game_ui boolean|nil
143145
---@return boolean

dist/library/modules/military.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
---@class dfhack.military
55
dfhack.military = {}
66

7+
-- could be extended straightforwardly by passing in entity
78
---@param assignment_id number
89
---@return df.squad
910
function dfhack.military.makeSquad(assignment_id) end

dist/library/modules/screen.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,11 @@
1010
---@field _doSimulateInput function
1111
dfhack.screen = {}
1212

13+
-- returns ui grid coordinates, even if the game map is scaled differently
1314
---@return df.coord2d
1415
function dfhack.screen.getMousePos() end
1516

17+
-- returns the screen pixel coordinates
1618
---@return df.coord2d
1719
function dfhack.screen.getMousePixels() end
1820

dist/library/modules/units.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function dfhack.units.getOuterContainerRef(unit, init_ref) end
1919
---@return boolean
2020
function dfhack.units.getNoblePositions(pvec, unit) end
2121

22+
-- returns index of creature actually read or -1 if no creature can be found
2223
---@param x1 number
2324
---@param y1 number
2425
---@param z1 number
@@ -74,14 +75,17 @@ function dfhack.units.isResident(unit, include_insane) end
7475
---@return boolean
7576
function dfhack.units.isFortControlled(unit) end
7677

78+
-- (don't try to pasture/slaughter random untame animals)
7779
---@param unit df.unit
7880
---@return boolean
7981
function dfhack.units.isOwnCiv(unit) end
8082

83+
-- check if creature belongs to the player's group
8184
---@param unit df.unit
8285
---@return boolean
8386
function dfhack.units.isOwnGroup(unit) end
8487

88+
-- (in combination with check for civ helps to filter out own dwarves)
8589
---@param unit df.unit
8690
---@return boolean
8791
function dfhack.units.isOwnRace(unit) end
@@ -162,10 +166,12 @@ function dfhack.units.isTrainableWar(unit) end
162166
---@return boolean
163167
function dfhack.units.isTrained(unit) end
164168

169+
-- check for profession "hunting creature"
165170
---@param unit df.unit
166171
---@return boolean
167172
function dfhack.units.isHunter(unit) end
168173

174+
-- check for profession "war creature"
169175
---@param unit df.unit
170176
---@return boolean
171177
function dfhack.units.isWar(unit) end
@@ -178,6 +184,7 @@ function dfhack.units.isTame(unit) end
178184
---@return boolean
179185
function dfhack.units.isTamable(unit) end
180186

187+
-- seems to be the only way to really tell if it's completely safe to autonestbox it (training can revert)
181188
---@param unit df.unit
182189
---@return boolean
183190
function dfhack.units.isDomesticated(unit) end
@@ -238,6 +245,7 @@ function dfhack.units.isForest(unit) end
238245
---@return boolean
239246
function dfhack.units.isMischievous(unit) end
240247

248+
-- check if unit is marked as available for adoption
241249
---@param unit df.unit
242250
---@return boolean
243251
function dfhack.units.isAvailableForAdoption(unit) end
@@ -472,6 +480,7 @@ function dfhack.units.getRaceName(unit) end
472480
---@return string
473481
function dfhack.units.getRaceNamePlural(unit) end
474482

483+
-- get race name by id or unit pointer
475484
---@param id number
476485
---@return string
477486
function dfhack.units.getRaceNameById(id) end

lib/cpp.rb

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,8 @@ def parse_cpp_modules(entry_point)
7575
function_name = name.gsub(/"/, '').strip
7676
signature_name = signature.gsub(/"/, '').strip
7777

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

8382
file[/^(?:static\s)?(?:DFHACK_EXPORT\s)?(\S+).*?#{signature_name}\s?\(([^)]+)?\)/]
@@ -97,9 +96,8 @@ def parse_cpp_modules(entry_point)
9796
function_name = name.gsub(/"/, '').strip
9897
signature_name = signature.gsub(/"/, '').strip
9998

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

105103
functions << DFHackLuaDefinitions::CPP.parse_function(Regexp.last_match, module_name:, prefix:,
@@ -110,7 +108,7 @@ def parse_cpp_modules(entry_point)
110108
function_name = Regexp.last_match(1) if function_name =~ /,\s?(\S+)/
111109
signature = "#{namespace}#{function_name}"
112110

113-
module_file[/^(?:static\s)?(?:DFHACK_EXPORT\s)?(\S+).*?#{signature}\s?\(([^)]+)?\)/]
111+
module_file[%r{(//.*\R)?^(?:static\s)?(?:DFHACK_EXPORT\s)?(\S+).*?#{signature}\s?\(([^)]+)?\)}]
114112

115113
next unless Regexp.last_match
116114

@@ -156,11 +154,16 @@ def parse_function(match, module_name:, prefix:, function_name:)
156154
annotation = []
157155

158156
captures = match.captures
159-
return_type = parse_type(captures[0])
157+
if captures[0]
158+
comment = captures[0].gsub(%r{^//\s*}, '').strip
159+
annotation << DFHackLuaDefinitions::Annotation.multiline_comment(comment)
160+
end
161+
162+
return_type = parse_type(captures[1])
160163
arguments = []
161164

162-
if captures[1]
163-
arguments = captures[1].split(/,(?![^<>]*>)/).reject.with_index do |arg, index|
165+
if captures[2]
166+
arguments = captures[2].split(/,(?![^<>]*>)/).reject.with_index do |arg, index|
164167
arg[/(&\s*out)|lua_State/] && index.zero?
165168
end
166169

0 commit comments

Comments
 (0)