summaryrefslogtreecommitdiff
path: root/lua/strict.lua
blob: 1c70442f05fbabc6ad78f2f1de139870aabb159b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
local _private = {}

function strict_read(table, key)
   if _private[key] then
      return _private[key]
   else
      error("Invalid key: " .. key)
   end
end

function strict_write(table, key, value)
   if _private[key] then
      error("Duplicate key: " .. key)
   else
      _private[key] = value
   end
end

local mt = {
   __index = strict_read,
   __newindex = strict_write
}

treasure = {}
setmetatable(treasure, mt)