summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2022-05-28 22:56:35 +0800
committer最萌小汐 <sumneko@hotmail.com>2022-05-28 22:56:35 +0800
commit7eaec047d708e84a7c29dd9d70e306d90fac412d (patch)
treea79282766b8a472494d5ba1f2c65e025b39a66fb
parent9060bc4b2c3f40145b91fc0423de31b07161b5f5 (diff)
downloadlua-language-server-7eaec047d708e84a7c29dd9d70e306d90fac412d.zip
update meta files for `love2d` and `lovr`
-rw-r--r--meta/3rd/love2d/library/love.graphics.lua2
-rw-r--r--meta/3rd/love2d/library/love.window.lua2
-rw-r--r--meta/3rd/lovr/library/lovr.audio.lua2
-rw-r--r--meta/3rd/lovr/library/lovr.graphics.lua2
-rw-r--r--tools/love-api.lua19
-rw-r--r--tools/lovr-api.lua16
6 files changed, 30 insertions, 13 deletions
diff --git a/meta/3rd/love2d/library/love.graphics.lua b/meta/3rd/love2d/library/love.graphics.lua
index 056cfef1..1528a181 100644
--- a/meta/3rd/love2d/library/love.graphics.lua
+++ b/meta/3rd/love2d/library/love.graphics.lua
@@ -569,7 +569,7 @@ function love.graphics.newFont(filename) end
---@overload fun(imageData: love.ImageData, flags: table):love.Image
---@overload fun(compressedImageData: love.CompressedImageData, flags: table):love.Image
---@param filename string # The filepath to the image file.
----@param flags {dpiscale: number, linear: boolean, mipmaps: boolean} # A table containing the following fields:
+---@param flags? {dpiscale: number, linear: boolean, mipmaps: boolean} # A table containing the following fields:
---@return love.Image image # A new Image object which can be drawn on screen.
function love.graphics.newImage(filename, flags) end
diff --git a/meta/3rd/love2d/library/love.window.lua b/meta/3rd/love2d/library/love.window.lua
index 0fd99213..0e9004d4 100644
--- a/meta/3rd/love2d/library/love.window.lua
+++ b/meta/3rd/love2d/library/love.window.lua
@@ -229,7 +229,7 @@ function love.window.setIcon(imagedata) end
---
---@param width number # Display width.
---@param height number # Display height.
----@param flags {fullscreen: boolean, fullscreentype: love.FullscreenType, vsync: boolean, msaa: number, stencil: boolean, depth: number, resizable: boolean, borderless: boolean, centered: boolean, display: number, minwidth: number, minheight: number, highdpi: boolean, x: number, y: number, usedpiscale: boolean, srgb: boolean} # The flags table with the options:
+---@param flags? {fullscreen: boolean, fullscreentype: love.FullscreenType, vsync: boolean, msaa: number, stencil: boolean, depth: number, resizable: boolean, borderless: boolean, centered: boolean, display: number, minwidth: number, minheight: number, highdpi: boolean, x: number, y: number, usedpiscale: boolean, srgb: boolean} # The flags table with the options:
---@return boolean success # True if successful, false otherwise.
function love.window.setMode(width, height, flags) end
diff --git a/meta/3rd/lovr/library/lovr.audio.lua b/meta/3rd/lovr/library/lovr.audio.lua
index baac445b..e948e0d4 100644
--- a/meta/3rd/lovr/library/lovr.audio.lua
+++ b/meta/3rd/lovr/library/lovr.audio.lua
@@ -186,7 +186,7 @@ function lovr.audio.isStarted(type) end
---@overload fun(blob: lovr.Blob, options: table):lovr.Source
---@overload fun(sound: lovr.Sound, options: table):lovr.Source
---@param filename string # The filename of the sound to load.
----@param options {decode: boolean, effects: table} # Optional options.
+---@param options? {decode: boolean, effects: table} # Optional options.
---@return lovr.Source source # The new Source.
function lovr.audio.newSource(filename, options) end
diff --git a/meta/3rd/lovr/library/lovr.graphics.lua b/meta/3rd/lovr/library/lovr.graphics.lua
index 42a859a5..658bf2b3 100644
--- a/meta/3rd/lovr/library/lovr.graphics.lua
+++ b/meta/3rd/lovr/library/lovr.graphics.lua
@@ -129,7 +129,7 @@ function lovr.graphics.compute(shader, x, y, z) end
---
---The window must be created before any `lovr.graphics` functions can be used.
---
----@param flags {width: number, height: number, fullscreen: boolean, resizable: boolean, msaa: number, title: string, icon: string, vsync: number} # Flags to customize the window's appearance and behavior.
+---@param flags? {width: number, height: number, fullscreen: boolean, resizable: boolean, msaa: number, title: string, icon: string, vsync: number} # Flags to customize the window's appearance and behavior.
function lovr.graphics.createWindow(flags) end
---
diff --git a/tools/love-api.lua b/tools/love-api.lua
index 38653e68..31284cd6 100644
--- a/tools/love-api.lua
+++ b/tools/love-api.lua
@@ -51,13 +51,16 @@ local function formatIndex(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
+ 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
@@ -156,7 +159,7 @@ 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)
+ local optional = param.type == 'table' and isTableOptional(param.table) or (param.default ~= nil)
text[#text+1] = ('---@param %s%s %s # %s'):format(
paramName,
optional and '?' or '',
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
)