lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On Wed, Jul 4, 2018, 4:22 PM Egor Skriptunoff <> wrote:
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 $".

A recipe for disaster, imho. Again, you're defining a different language. Let's call it lua$. Now whenever I look at Lua code the first thing I have to do is figger out if it is genuine Lua, or lua$. No, thanks.

- 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.