From 9f546bac3dc4327650711929765981c0877c291f Mon Sep 17 00:00:00 2001 From: C3pa <41503714+C3pa@users.noreply.github.com> Date: Sat, 28 May 2022 09:22:34 +0200 Subject: Update love-api builder --- tools/love-api.lua | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'tools/love-api.lua') diff --git a/tools/love-api.lua b/tools/love-api.lua index 54369acb..6a0f1f01 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,6 +156,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 + if param.type == 'table' then + param.default = isTableOptional(param.table) + end text[#text+1] = ('---@param %s%s %s # %s'):format( paramName, param.default == nil and '' or '?', -- cgit v1.2.3