aboutsummaryrefslogtreecommitdiff
path: root/.config/awesome/quarrel/const.lua
blob: 342ae412fc834cac4dfb2d88055c695a5037cf1c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
local M = {}

---@param protected (fun(): table) | table
function M.protect(protected)
    ---@type table
    local tbl
    if type(protected) == "table" then
        tbl = protected
    elseif type(protected) == "function" then
        tbl = protected()
    else
        error("expected a table or a function that returns a table, got " .. type(protected), 2)
    end
    return setmetatable({}, {
        __index = tbl,
        __newindex = function(_, k, v)
            error("attempted to change constant " .. tostring(k) .. " to " .. tostring(v), 2)
        end,
    })
end

return M