🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

constants in LUA?

Started by
0 comments, last by quasty 20 years, 2 months ago
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?
Advertisement
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]

This topic is closed to new replies.

Advertisement