mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
25 lines
379 B
Lua
25 lines
379 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
|
||
|
|
|
||
|
|
|
||
|
|
return F
|