Strict mode in lua
Moderator: Forum Moderators
Strict mode in lua
One change which I pushed recently to master was to add "strict globals" mode to wesnoth's lua.
Strict globals is a standard modification to the lua environment, documented on the lua users wiki and distributed with lua (http://www.lua.org/extras/5.2/strict.lua). It makes lua treat it as an error if you try to access a global variable that does not exist, rather than silently return nil. There are two main reasons that I did this:
1. Helps users (and us) to write bug-free code.
2. Makes the lua interpreter much more useful. It was suggested from reading documentation of "ilua", an extra which is meant to make lua run much more comfortably in an interactive interpreter. (http://lua-users.org/wiki/InteractiveLua) The version I merged is based on this version.
When I first learned of strict mode I was not keen on the idea, but I have gradually warmed to it. I now think it is the simplest and most elegant solution to these problems.
If you don't like strict mode and you want to revert it, that's fine -- I'm writing this post because at least one dev doesn't like it, and it seems hard to have a complete discussion on the irc channel. Compatibility breaking changes are bad because they create work for maintainers, but it seems that this change actually will reduce the work for everyone in the long run, since it adds a safety mechanism to catch bugs (and has already done so in core lua), so to me strict mode seems worthwhile. If you want to revert, please explain why it isn't, and please suggest an alternate way that you think the lua interpreter should work.
Strict globals is a standard modification to the lua environment, documented on the lua users wiki and distributed with lua (http://www.lua.org/extras/5.2/strict.lua). It makes lua treat it as an error if you try to access a global variable that does not exist, rather than silently return nil. There are two main reasons that I did this:
1. Helps users (and us) to write bug-free code.
2. Makes the lua interpreter much more useful. It was suggested from reading documentation of "ilua", an extra which is meant to make lua run much more comfortably in an interactive interpreter. (http://lua-users.org/wiki/InteractiveLua) The version I merged is based on this version.
Helps to catch bugs
Helps the lua interpreter
Fixing undesired strict mode errors
When I first learned of strict mode I was not keen on the idea, but I have gradually warmed to it. I now think it is the simplest and most elegant solution to these problems.
If you don't like strict mode and you want to revert it, that's fine -- I'm writing this post because at least one dev doesn't like it, and it seems hard to have a complete discussion on the irc channel. Compatibility breaking changes are bad because they create work for maintainers, but it seems that this change actually will reduce the work for everyone in the long run, since it adds a safety mechanism to catch bugs (and has already done so in core lua), so to me strict mode seems worthwhile. If you want to revert, please explain why it isn't, and please suggest an alternate way that you think the lua interpreter should work.