diff options
Diffstat (limited to 'tools/lovr-api.lua')
-rw-r--r-- | tools/lovr-api.lua | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/tools/lovr-api.lua b/tools/lovr-api.lua index ca7c414e..d61bfdb7 100644 --- a/tools/lovr-api.lua +++ b/tools/lovr-api.lua @@ -51,6 +51,19 @@ 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 +end + local buildType local function buildDocTable(tbl) @@ -150,9 +163,10 @@ local function buildFunction(func, 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 ) |