官术网_书友最值得收藏!

Global scope

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 -- global
do
bar = 8 -- global
end
print ("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 file
local x = 9 -- local to the .lua file being executed
do
local bar = 8 -- local to the current do/end chunk
end
主站蜘蛛池模板: 屏东市| 高雄市| 绵竹市| 林口县| 临沧市| 新河县| 宿松县| 纳雍县| 五峰| 马鞍山市| 遵义县| 长武县| 永济市| 象山县| 密山市| 商城县| 嵩明县| 江陵县| 新乡县| 丰顺县| 林州市| 富裕县| 博野县| 会理县| 会理县| 利辛县| 长治市| 疏附县| 赫章县| 定南县| 东乌| 浙江省| 鄂托克旗| 历史| 冷水江市| 旌德县| 镇平县| 绥德县| 资溪县| 关岭| 郑州市|