summaryrefslogtreecommitdiff
path: root/lua/strict.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/strict.lua')
-rw-r--r--lua/strict.lua25
1 files changed, 25 insertions, 0 deletions
diff --git a/lua/strict.lua b/lua/strict.lua
new file mode 100644
index 0000000..1c70442
--- /dev/null
+++ b/lua/strict.lua
@@ -0,0 +1,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)