Skip to content

Commit a570167

Browse files
committed
Add optional for overloads
1 parent 7eaec04 commit a570167

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

tools/love-api.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,11 @@ local function buildDocFunc(variant, overload)
124124
if param.name == '...' then
125125
params[#params+1] = '...'
126126
else
127+
local optional = (param.type == 'table' and isTableOptional(param.table) or (param.default ~= nil)) and '?' or ''
127128
if param.name:find '^[\'"]' then
128-
params[#params+1] = ('%s: %s|%q'):format(param.name:sub(2, -2), getTypeName(param.type), param.name)
129+
params[#params+1] = ('%s%s: %s|%q'):format(param.name:sub(2, -2), optional, getTypeName(param.type), param.name)
129130
else
130-
params[#params+1] = ('%s: %s'):format(param.name, getTypeName(param.type))
131+
params[#params+1] = ('%s%s: %s'):format(param.name, optional, getTypeName(param.type))
131132
end
132133
end
133134
end

tools/lovr-api.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,11 @@ local function buildDocFunc(variant, overload)
128128
if param.name == '...' then
129129
params[#params+1] = '...'
130130
else
131+
local optional = (param.type == 'table' and isTableOptional(param.table) or (param.default ~= nil)) and '?' or ''
131132
if param.name:find '^[\'"]' then
132-
params[#params+1] = ('%s: %s|%q'):format(param.name:sub(2, -2), getTypeName(param.type), param.name)
133+
params[#params+1] = ('%s%s: %s|%q'):format(param.name:sub(2, -2), optional, getTypeName(param.type), param.name)
133134
else
134-
params[#params+1] = ('%s: %s'):format(param.name, getTypeName(param.type))
135+
params[#params+1] = ('%s%s: %s'):format(param.name, optional, getTypeName(param.type))
135136
end
136137
end
137138
end

0 commit comments

Comments
 (0)