The visibility of variables in Lua is a bit different than in C#. The same variable name can be used within the inner block without any naming issues. Lets see how this is in practice

If a variable is declared and the outer-most scope it will be considered a global one. A scope of variable is defined from it’s declaration to the last instruction in the same block as the declaration.

The local x = x defines a new variable with new scope and with initial value taken from the outer scope.

Variables can also be accessed within the functions defined within their inner scope.

Al the anonymous functions (10) share the same variable x with value 10 but each of them has a separate variable y.

Founder of Octal Solutions a .NET software house.
Passionate dev, blogger, occasionally speaker, one of the leaders of Wroc.NET user group. Microsoft MVP. Podcaster –