Skip to content

Commit 3d7aa8e

Browse files
committed
Fix pointer as first argument
1 parent 1d61bd3 commit 3d7aa8e

File tree

5 files changed

+29
-31
lines changed

5 files changed

+29
-31
lines changed

dist/library/modules/buildings.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,13 @@ function dfhack.buildings.findAtTile(pos) end
1414
---@return boolean
1515
function dfhack.buildings.findCivzonesAt(pvec, pos) end
1616

17-
---@param size df.coord2d
1817
---@param center df.coord2d
1918
---@param type df.building_type
2019
---@param subtype integer
2120
---@param custom integer
2221
---@param direction integer
23-
---@return boolean
24-
function dfhack.buildings.getCorrectSize(size, center, type, subtype, custom, direction) end
22+
---@return df.coord2d size
23+
function dfhack.buildings.getCorrectSize(center, type, subtype, custom, direction) end
2524

2625
---@param coord df.coord
2726
---@return df.building

dist/library/modules/items.lua

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,22 @@ dfhack.items = {}
1515
---@return df.coord
1616
function dfhack.items.getPosition(item) end
1717

18-
---@param spec_ref df.specific_ref
1918
---@param item df.item
2019
---@param init_ref boolean|nil
21-
---@return nil
22-
function dfhack.items.getOuterContainerRef(spec_ref, item, init_ref) end
20+
---@return df.specific_ref spec_ref
21+
function dfhack.items.getOuterContainerRef(item, init_ref) end
2322

2423
---@param item df.item
2524
---@param items { [integer]: df.item }
2625
---@return nil
2726
function dfhack.items.getContainedItems(item, items) end
2827

29-
---@param mc unknown
3028
---@param item df.item
3129
---@param building df.building_actual
3230
---@param use_mode df.building_item_role_type
3331
---@param force_in_building boolean|nil
34-
---@return boolean
35-
function dfhack.items.moveToBuilding(mc, item, building, use_mode, force_in_building) end
32+
---@return unknown
33+
function dfhack.items.moveToBuilding(item, building, use_mode, force_in_building) end
3634

3735
---@param unit df.unit
3836
---@param item_type df.item_type

dist/library/modules/screen.lua

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,12 @@ function dfhack.screen.getMousePixels() end
1313
---@return df.coord2d
1414
function dfhack.screen.getWindowSize() end
1515

16-
---@param pen unknown
1716
---@param x integer
1817
---@param y integer
1918
---@param map boolean|nil
2019
---@param df::graphic_viewportst::texpos_field number
21-
---@return boolean
22-
function dfhack.screen.paintTile(pen, x, y, map, df::graphic_viewportst::texpos_field) end
20+
---@return unknown
21+
function dfhack.screen.paintTile(x, y, map, df::graphic_viewportst::texpos_field) end
2322

2423
---@param x integer
2524
---@param y integer
@@ -28,30 +27,27 @@ function dfhack.screen.paintTile(pen, x, y, map, df::graphic_viewportst::texpos_
2827
---@return unknown
2928
function dfhack.screen.readTile(x, y, map, df::graphic_viewportst::texpos_field) end
3029

31-
---@param pen unknown
3230
---@param x integer
3331
---@param y integer
3432
---@param text string
3533
---@param map boolean|nil
36-
---@return boolean
37-
function dfhack.screen.paintString(pen, x, y, text, map) end
34+
---@return unknown
35+
function dfhack.screen.paintString(x, y, text, map) end
3836

39-
---@param pen unknown
4037
---@param x1 integer
4138
---@param y1 integer
4239
---@param x2 integer
4340
---@param y2 integer
4441
---@param map boolean|nil
45-
---@return boolean
46-
function dfhack.screen.fillRect(pen, x1, y1, x2, y2, map) end
42+
---@return unknown
43+
function dfhack.screen.fillRect(x1, y1, x2, y2, map) end
4744

48-
---@param pagename string
4945
---@param x integer
5046
---@param y integer
5147
---@param ptile integer
5248
---@param pgs integer
53-
---@return boolean
54-
function dfhack.screen.findGraphicsTile(pagename, x, y, ptile, pgs) end
49+
---@return unknown
50+
function dfhack.screen.findGraphicsTile(x, y, ptile, pgs) end
5551

5652
---@param key df.interface_key
5753
---@return integer

dist/library/modules/units.lua

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,34 @@ dfhack.units = {}
88
---@return df.coord
99
function dfhack.units.getPosition(unit) end
1010

11-
---@param spec_ref df.specific_ref
1211
---@param unit df.unit
1312
---@param init_ref boolean|nil
14-
---@return nil
15-
function dfhack.units.getOuterContainerRef(spec_ref, unit, init_ref) end
13+
---@return df.specific_ref spec_ref
14+
function dfhack.units.getOuterContainerRef(unit, init_ref) end
1615

1716
---@param pvec { [integer]: unknown }
1817
---@param unit df.unit
1918
---@return boolean
2019
function dfhack.units.getNoblePositions(pvec, unit) end
2120

22-
---@param units { [integer]: df.unit }
2321
---@param x1 number
2422
---@param y1 number
2523
---@param z1 number
2624
---@param x2 number
2725
---@param y2 number
2826
---@param z2 number
29-
---@return boolean
30-
function dfhack.units.getUnitsInBox(units, x1, y1, z1, x2, y2, z2) end
27+
---@return { [integer]: df.unit }
28+
function dfhack.units.getUnitsInBox(x1, y1, z1, x2, y2, z2) end
3129

3230
---@param citizens { [integer]: df.unit }
3331
---@param exclude_residents boolean|nil
3432
---@param include_insane boolean|nil
3533
---@return boolean
3634
function dfhack.units.getCitizens(citizens, exclude_residents, include_insane) end
3735

38-
---@param units { [integer]: df.unit }
3936
---@param noble string
40-
---@return boolean
41-
function dfhack.units.getUnitsByNobleRole(units, noble) end
37+
---@return { [integer]: df.unit }
38+
function dfhack.units.getUnitsByNobleRole(noble) end
4239

4340
---@param unit df.unit
4441
---@param trainer_id number

lib/cpp.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,10 +154,18 @@ def parse_function(match, module_name:, prefix:, function_name:)
154154
arguments = []
155155

156156
if captures[1]
157-
# TODO: Naming convention or actual compiler behaviour?
158157
arguments = captures[1].split(/,(?![^<>]*>)/).reject.with_index do |arg, index|
159158
arg[/(&\s*out)|lua_State/] && index.zero?
160159
end
160+
161+
# We're accounting for pointers as first arguments _usually_ being a
162+
# way of avoiding copy semantics. When these are wrapped as Lua
163+
# functions the pointer is returned.
164+
if /&\w+/.match(arguments[0])
165+
return_type = parse_type(arguments[0].gsub(%r{/\*[^/]+/}, '').gsub(/const\s+|[*&]/, '').strip)
166+
arguments.shift(1)
167+
end
168+
161169
arguments = arguments.map { |arg| arg.gsub(%r{/\*[^/]+/}, '').gsub(/const\s+|[*&]/, '').strip }
162170
arguments = arguments&.map do |argument|
163171
type, _, name = argument.rpartition(' ')

0 commit comments

Comments
 (0)