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.lua13
1 files changed, 12 insertions, 1 deletions
diff --git a/tools/love-api.lua b/tools/love-api.lua
index 54369acb..38653e68 100644
--- a/tools/love-api.lua
+++ b/tools/love-api.lua
@@ -50,6 +50,16 @@ local function formatIndex(key)
return ('[%q]'):format(key)
end
+local function isTableOptional(tbl)
+ local optional = true
+ for _, field in ipairs(tbl) do
+ if field.default == nil then
+ optional = nil
+ end
+ end
+ return optional
+end
+
local buildType
local function buildDocTable(tbl)
@@ -146,9 +156,10 @@ 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,
- param.default == nil and '' or '?',
+ optional and '?' or '',
buildType(param),
param.description
)