Files
neovim/runtime/lua/vim/F.lua
Gregory Anders c2a211b8e3 docs: make Lua docstrings consistent #15255
The official developer documentation in in :h dev-lua-doc specifies to
use "--@" for special/magic tokens. However, this format is not
consistent with EmmyLua notation (used by some Lua language servers) nor
with the C version of the magic docstring tokens which use three comment
characters.

Further, the code base is currently split between usage of "--@",
"---@", and "--- @". In an effort to remain consistent, change all Lua
magic tokens to use "---@" and update the developer documentation
accordingly.
2021-08-22 13:55:28 -07:00

32 lines
535 B
Lua

local F = {}
--- Returns {a} if it is not nil, otherwise returns {b}.
---
---@param a
---@param b
function F.if_nil(a, b)
if a == nil then return b end
return a
end
-- Use in combination with pcall
function F.ok_or_nil(status, ...)
if not status then return end
return ...
end
-- Nil pcall.
function F.npcall(fn, ...)
return F.ok_or_nil(pcall(fn, ...))
end
--- Wrap a function to return nil if it fails, otherwise the value
function F.nil_wrap(fn)
return function(...)
return F.npcall(fn, ...)
end
end
return F