diff options
Diffstat (limited to '.config/awesome/quarrel/const.lua')
-rw-r--r-- | .config/awesome/quarrel/const.lua | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/.config/awesome/quarrel/const.lua b/.config/awesome/quarrel/const.lua new file mode 100644 index 0000000..342ae41 --- /dev/null +++ b/.config/awesome/quarrel/const.lua @@ -0,0 +1,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 |