diff options
author | Guillermo Ramos | 2014-07-01 20:51:07 +0200 |
---|---|---|
committer | Guillermo Ramos | 2014-07-01 20:51:07 +0200 |
commit | f3c354d396a38033dac28ece6f6220e75cef5aec (patch) | |
tree | 98c0977e8152472463cd2947589f725c9d5e2551 /lua/strict.lua | |
parent | aef238a0600c5cb775bb371dbb2463fd0381bff9 (diff) | |
download | 7l-f3c354d396a38033dac28ece6f6220e75cef5aec.tar.gz |
[Lua] Día 2 (sin terminar)
Diffstat (limited to 'lua/strict.lua')
-rw-r--r-- | lua/strict.lua | 25 |
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) |