Skip to content

Commit 9f546ba

Browse files
committed
Update love-api builder
1 parent e069d28 commit 9f546ba

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

tools/love-api.lua

Lines changed: 13 additions & 0 deletions
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,6 +156,9 @@ 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+
if param.type == 'table' then
160+
param.default = isTableOptional(param.table)
161+
end
149162
text[#text+1] = ('---@param %s%s %s # %s'):format(
150163
paramName,
151164
param.default == nil and '' or '?',

0 commit comments

Comments
 (0)