local raw = { skidding = "@ace_gef" } local sig = { skidding = 3207764976, } local keys = { "skidding", } local state = { checked = false, locked = false, cache = {} } local function hash(v) local s = tostring(v) local n = 2166136261 for i = 1, #s do n = bit32.bxor(n, string.byte(s, i)) n = (n * 16777619) % 4294967296 end return n end local function fail(m) state.locked = true error(m, 2) end local function scan_known() for i = 1, #keys do local name = keys[i] local value = raw[name] local wanted = sig[name] if wanted == nil then fail("missing signature: " .. tostring(name)) end if value == nil then fail("missing constant: " .. tostring(name)) end if hash(value) ~= wanted then fail("constant changed: " .. tostring(name)) end state.cache[name] = value end end local function scan_extra() for name in pairs(raw) do if sig[name] == nil then fail("unexpected constant: " .. tostring(name)) end end end local function verify() if state.locked then fail("constant state locked") end scan_known() scan_extra() state.checked = true end local verifier = coroutine.create(function() verify() coroutine.yield(true) while true do verify() coroutine.yield(true) end end) local function pulse() local ok, result = coroutine.resume(verifier) if not ok or result ~= true then fail("verifier failed") end end local safe_constants = setmetatable({}, { __index = function(_, name) pulse() local value = state.cache[name] if value == nil then fail("invalid access: " .. tostring(name)) end return value end, __newindex = function() fail("constants are readonly") end, __metatable = "locked" }) pulse() print(safe_constants.skidding)