Advertisement Jump to content


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


constants in LUA?

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

If you intended to correct an error in the post then please contact us.

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 this post

Link to post
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:

local constanttable = { pi = 3.14159, appname = "tetris"}
const = setmetatable({}, {__index = constanttable,
__newindex = function () error ("Attempt to modify constant") 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]

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!