Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion tools/love-api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
)
Expand Down