Skip to content

Instantly share code, notes, and snippets.

@nilium
Created August 19, 2009 18:34
Show Gist options
  • Save nilium/170556 to your computer and use it in GitHub Desktop.
Save nilium/170556 to your computer and use it in GitHub Desktop.
-- 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