Lua Programming/How to Lua/scope

There are two levels of variable scope in luaEdit

The lua programming language offers two levels of variable scope:

  • global - Global variables exist always and are visible everywhere from within the program.
  • local - Local variables exist only within the block in which they are created

Variable scopeEdit

Variables are global by defaultEdit

In lua, variables are global by default, unless they are declared as local.

Local variables have lexical scopeEdit

In lua, local variables have lexical scope and are visible to functions defined inside the variable scope.

Function scopeEdit

The outer scope (other than the global scope) of a nested function may not be accessed.

Last modified on 9 February 2011, at 19:56