summaryrefslogtreecommitdiff
path: root/lua/strict.lua
diff options
context:
space:
mode:
authorGuillermo Ramos2014-07-01 20:51:07 +0200
committerGuillermo Ramos2014-07-01 20:51:07 +0200
commitf3c354d396a38033dac28ece6f6220e75cef5aec (patch)
tree98c0977e8152472463cd2947589f725c9d5e2551 /lua/strict.lua
parentaef238a0600c5cb775bb371dbb2463fd0381bff9 (diff)
download7l-f3c354d396a38033dac28ece6f6220e75cef5aec.tar.gz
[Lua] Día 2 (sin terminar)
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)