35 lines
581 B
Lua
35 lines
581 B
Lua
|
---@class lazyvim.util.inject
|
||
|
local M = {}
|
||
|
|
||
|
---@generic A: any
|
||
|
---@generic B: any
|
||
|
---@generic C: any
|
||
|
---@generic F: function
|
||
|
---@param fn F|fun(a:A, b:B, c:C)
|
||
|
---@param wrapper fun(a:A, b:B, c:C): boolean?
|
||
|
---@return F
|
||
|
function M.args(fn, wrapper)
|
||
|
return function(...)
|
||
|
if wrapper(...) == false then
|
||
|
return
|
||
|
end
|
||
|
return fn(...)
|
||
|
end
|
||
|
end
|
||
|
|
||
|
function M.get_upvalue(func, name)
|
||
|
local i = 1
|
||
|
while true do
|
||
|
local n, v = debug.getupvalue(func, i)
|
||
|
if not n then
|
||
|
break
|
||
|
end
|
||
|
if n == name then
|
||
|
return v
|
||
|
end
|
||
|
i = i + 1
|
||
|
end
|
||
|
end
|
||
|
|
||
|
return M
|