July 2018
Beginner
202 pages
5h 42m
English
Notice in the last few examples the use of the local keyword. If you omit the local keyword, the variable is considered to be in global scope. Without the local keyword, the variable is global, no matter what chunk it is in:
foo = 7 -- globaldo bar = 8 -- globalendprint ("foo: " .. foo)print ("bar: " .. bar)
The global scope is interesting. It is not tied directly to a Lua file. The local keyword can be used outside any do/end chunks to make a variable local to the file it is loaded from:
foo = 7 -- global, can be accesssed from any loaded lua filelocal x = 9 -- local to the .lua file being executeddo local bar = 8 -- local to the current do/end chunkend