Created
August 19, 2009 18:34
-
-
Save nilium/170556 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- constable.lua | |
function BuildConstantsTable(kvpairs) | |
local t_Const={} | |
for k,v in next,kvpairs,nil do | |
t_Const[k]=v | |
end | |
local consts = {} | |
setmetatable(consts, | |
{ | |
constants = t_Const; | |
__index=function(table, key) | |
return getmetatable(table).constants[key] | |
end; | |
__newindex=function(table, key) | |
error("Attempt to rewrite constant "..key) | |
end; | |
} ) | |
return consts | |
end | |
Keys = BuildConstantsTable({KEY_UP=5,KEY_DOWN=10,KEY_LEFT=20,KEY_RIGHT=40}) | |
print(Keys.KEY_UP) | |
Keys.KEY_UP=20 | |
print(Keys.KEY_UP) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment