aboutsummaryrefslogtreecommitdiff
path: root/.config/awesome/quarrel/delegate.lua
blob: 54db786396ac8275e5f8614f6a273e61443310cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
--- Capture `fn`'s upvalues and pass to `delegate`
---@param delegate fun(env: table<string, any>, _: ...): ...
---@param fn function
---@return fun(...): ...
return function(delegate, fn)
    local upvalues = {}
    for i = 1, debug.getinfo(fn, "u").nups do
        local name, value = debug.getupvalue(fn, i)
        upvalues[name] = value
    end
    return function(...)
        return delegate(upvalues, ...)
    end
end