From b3530d7c4a102935fa26498a160ee1dc6c1e9c03 Mon Sep 17 00:00:00 2001 From: delta Date: Fri, 4 Jul 2025 00:38:29 +0200 Subject: :3 --- .config/awesome/quarrel/const.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 .config/awesome/quarrel/const.lua (limited to '.config/awesome/quarrel/const.lua') 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 -- cgit v1.2.3