On Wed, Jul 4, 2018 at 9:36 AM, Steven K. wrote:Lua is used as embedded scripting language.I'm using Lua mostly embedded, just some globals to work and life with the environment. At this point if view, where are the benefits for me?
You are correct.
Indeed, the suggested new rule "all globals must start with $" wouldn't bring benefit to embedded/config/DSL scripts where local variables are used rarely or not used at all.
Lua must be able to successfully compile scripts using the old rule "allow $-less globals" (otherwise "global-only-variables users" would be unhappy).
To make all Lua users happy, "load()"/"lua_load()" should automatically select most suitable rule for a script being compiled:
- If at least one identifier starting with "$" was found in the script then this script must be compiled with new rule "all globals must start with $".
- If no such identifiers were found in the script, then this script must be compiled with old rule "allow $-less globals".
This way, 100% backward-compatibility would be achieved.
To implement rule auto-selection described above, there would be no need for two-pass compiler.When first $-less global name is encountered, we create an error message (a string) and save this string without raising an error.When first "$" lexem is encountered, we are raising error with saved string as error message.So, both groups of Lua users (those who love global-by-default and those who hate it) would obtain what they want.