#### Archived

This topic is now archived and is closed to further replies.

# constants in LUA?

This topic is 5032 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, aren''t there constants in LUA? wenn I was searching the ref-manual I was suprised that I couldn''t find anything about it?

##### Share on other sites
No, I don't suppose there are. You'll be stuck using normal variables. If you want good software engineering practices, Lua probably isn't the language for you. But if you want excellent scripting capabilities you're in luck.

Edit: You can probably make a metatable that will not allow you to change the members of a table. Modify __index but leave __newindex alone.

Edit #2: I didn't come up with this, but here's the simplest possible implementation:
dolocal constanttable = { pi = 3.14159, appname = "tetris"}const = setmetatable({}, {__index = constanttable,        __newindex = function () error ("Attempt to modify constant") end})end

And then you constants are accessible with something like const.pi, const.appname, etc.

[edited by - bobstevens on April 14, 2004 1:01:53 PM]