Jump to content
  • Advertisement

Archived

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

quasty

constants in LUA?

This topic is 5210 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
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:

do
local 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]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!