Skip to content

Commit 9060bc4

Browse files
authored
Merge pull request #1178 from C3pa/fix-1173-alternate
Alternate fix for #1173
2 parents 6cba3dd + 6803eb5 commit 9060bc4

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

tools/love-api.lua

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,16 @@ local function formatIndex(key)
5050
return ('[%q]'):format(key)
5151
end
5252

53+
local function isTableOptional(tbl)
54+
local optional = true
55+
for _, field in ipairs(tbl) do
56+
if field.default == nil then
57+
optional = nil
58+
end
59+
end
60+
return optional
61+
end
62+
5363
local buildType
5464

5565
local function buildDocTable(tbl)
@@ -146,9 +156,10 @@ local function buildFunction(func, node, typeName)
146156
for _, param in ipairs(func.variants[1].arguments or {}) do
147157
for paramName in param.name:gmatch '[%a_][%w_]*' do
148158
params[#params+1] = paramName
159+
local optional = param.type == 'table' and isTableOptional(param.table) or (param.default ~= nil)
149160
text[#text+1] = ('---@param %s%s %s # %s'):format(
150161
paramName,
151-
param.default == nil and '' or '?',
162+
optional and '?' or '',
152163
buildType(param),
153164
param.description
154165
)

0 commit comments

Comments
 (0)