mirror of
				https://github.com/neovim/neovim.git
				synced 2025-11-04 09:44:31 +00:00 
			
		
		
		
	Co-authored-by: Brede Yabo Sherling Kristensen <bredeyabo@hotmail.com> Co-authored-by: zeertzjq <zeertzjq@outlook.com> Co-authored-by: István Donkó <istvan.donko@gmail.com> Co-authored-by: Julian Berman <Julian@GrayVines.com> Co-authored-by: bryant <bryant@users.noreply.github.com> Co-authored-by: Michael Lingelbach <m.j.lbach@gmail.com> Co-authored-by: nlueb <9465658+nlueb@users.noreply.github.com> Co-authored-by: Leonhard Saam <leonhard.saam@yahoo.com> Co-authored-by: Jesse Wertheim <jaawerth@gmail.com> Co-authored-by: dm1try <me@dmitry.it> Co-authored-by: Jakub Łuczyński <doubleloop@o2.pl> Co-authored-by: Louis Lebrault <louis.lebrault@gmail.com> Co-authored-by: Brede Yabo Sherling Kristensen <bredeyabo@hotmail.com> Co-authored-by: zeertzjq <zeertzjq@outlook.com> Co-authored-by: István Donkó <istvan.donko@gmail.com> Co-authored-by: Julian Berman <Julian@GrayVines.com> Co-authored-by: bryant <bryant@users.noreply.github.com> Co-authored-by: Michael Lingelbach <m.j.lbach@gmail.com> Co-authored-by: nlueb <9465658+nlueb@users.noreply.github.com> Co-authored-by: Leonhard Saam <leonhard.saam@yahoo.com> Co-authored-by: Jesse Wertheim <jaawerth@gmail.com> Co-authored-by: dm1try <me@dmitry.it> Co-authored-by: Jakub Łuczyński <doubleloop@o2.pl> Co-authored-by: Louis Lebrault <louis.lebrault@gmail.com>
		
			
				
	
	
		
			41 lines
		
	
	
		
			775 B
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			775 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
 | 
						|
 | 
						|
--- like {...} except preserve the length explicitly
 | 
						|
function F.pack_len(...)
 | 
						|
  return {n=select('#', ...), ...}
 | 
						|
end
 | 
						|
 | 
						|
--- like unpack() but use the length set by F.pack_len if present
 | 
						|
function F.unpack_len(t)
 | 
						|
  return unpack(t, 1, t.n)
 | 
						|
end
 | 
						|
 | 
						|
return F
 |