summaryrefslogtreecommitdiff
path: root/tools/love-api.lua
diff options
context:
space:
mode:
Diffstat (limited to 'tools/love-api.lua')
-rw-r--r--tools/love-api.lua33
1 files changed, 17 insertions, 16 deletions
diff --git a/tools/love-api.lua b/tools/love-api.lua
index e217f5e5..c5f40288 100644
--- a/tools/love-api.lua
+++ b/tools/love-api.lua
@@ -50,17 +50,20 @@ local function formatIndex(key)
return ('[%q]'):format(key)
end
-local function isTableOptional(tbl)
- if not tbl then
- return false
- end
- local optional = true
- for _, field in ipairs(tbl) do
- if field.default == nil then
- optional = nil
- end
- end
- return optional
+local function getOptional(param)
+ if param.type == 'table' then
+ if not param.table then
+ return ''
+ end
+ for _, field in ipairs(param.table) do
+ if field.default == nil then
+ return ''
+ end
+ end
+ return '?'
+ else
+ return (param.default ~= nil) and '?' or ''
+ end
end
local buildType
@@ -124,11 +127,10 @@ local function buildDocFunc(variant, overload)
if param.name == '...' then
params[#params+1] = '...'
else
- local optional = (param.type == 'table' and isTableOptional(param.table) or (param.default ~= nil)) and '?' or ''
if param.name:find '^[\'"]' then
- params[#params+1] = ('%s%s: %s|%q'):format(param.name:sub(2, -2), optional, getTypeName(param.type), param.name)
+ params[#params+1] = ('%s%s: %s|%q'):format(param.name:sub(2, -2), getOptional(param), getTypeName(param.type), param.name)
else
- params[#params+1] = ('%s%s: %s'):format(param.name, optional, getTypeName(param.type))
+ params[#params+1] = ('%s%s: %s'):format(param.name, getOptional(param), getTypeName(param.type))
end
end
end
@@ -160,10 +162,9 @@ local function buildFunction(func, node, typeName)
for _, param in ipairs(func.variants[1].arguments or {}) do
for paramName in param.name:gmatch '[%a_][%w_]*' do
params[#params+1] = paramName
- local optional = param.type == 'table' and isTableOptional(param.table) or (param.default ~= nil)
text[#text+1] = ('---@param %s%s %s # %s'):format(
paramName,
- optional and '?' or '',
+ getOptional(param),
buildType(param),
param.description
)