-- create a proxy object for a table that prevents reading
-- empty keys, writing keys, and inspecting the metatable

local tableLock do
	local function invalidRead(_, k)
		error(("reading nonexistent element %q from locked table"):format(tostring(k)), 2)
	end

	local function invalidWrite(_, k)
		error(("writing key %q to locked table"):format(tostring(k)), 2)
	end

	local RW_LOCK = {
		__index = invalidRead,
		__newindex = invalidWrite,
	}

	function tableLock(tbl)
		setmetatable(tbl, RW_LOCK)

		return setmetatable(
			{},
			{
				__index = tbl,
				__newindex = invalidWrite,
				__metatable = "The metatable is locked",
			}
		)
	end
end
