From 98dc89fb24baa919c701313c8546cd4a06c643b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 20 Jul 2021 17:40:38 +0800 Subject: update --- tools/love-api.lua | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'tools/love-api.lua') diff --git a/tools/love-api.lua b/tools/love-api.lua index 5aec88e0..e4227d65 100644 --- a/tools/love-api.lua +++ b/tools/love-api.lua @@ -26,15 +26,19 @@ local knownTypes = { ['light userdata'] = 'lightuserdata' } -local function getTypeName(name) - if knownTypes[name] then - return knownTypes[name] +local function getTypeName(names) + local types = {} + for name in names:gmatch '[%a_][%w_]+' do + if name ~= 'or' then + types[#types+1] = knownTypes[name] or ('love.' .. name) + end end - return 'love.' .. name + return table.concat(types, '|') end local function buildType(param) if param.table then + -- TODO getTypeName(param.type) end return getTypeName(param.type) @@ -103,15 +107,20 @@ local function buildFile(class, defs) end for _, tp in ipairs(defs.types or {}) do + local mark = {} text[#text+1] = '' text[#text+1] = ('---@class %s%s'):format(getTypeName(tp.name), buildSuper(tp)) text[#text+1] = ('local %s = {}'):format(tp.name) for _, func in ipairs(tp.functions or {}) do - text[#text+1] = '' - text[#text+1] = buildFunction(class, func, tp.name .. ':') + if not mark[func.name] then + mark[func.name] = true + text[#text+1] = '' + text[#text+1] = buildFunction(class, func, tp.name .. ':') + end end end + -- TODO for _, tp in ipairs(defs.callbacks or {}) do text[#text+1] = '' text[#text+1] = ('---@type %s'):format(getTypeName(tp.name)) -- cgit v1.2.3