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

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
主站蜘蛛池模板: 潍坊市| 永吉县| 江北区| 平武县| 光泽县| 嘉鱼县| 祁东县| 介休市| 隆昌县| 抚顺市| 常德市| 昭平县| 额济纳旗| 龙泉市| 库车县| 贵溪市| 洛浦县| 阿拉尔市| 龙口市| 浦江县| 昌乐县| 荆州市| 铁岭县| 无棣县| 沁阳市| 杭州市| 招远市| 大安市| 逊克县| 柳林县| 连江县| 和顺县| 安阳市| 枣庄市| 吐鲁番市| 桂东县| 锡林浩特市| 晋城| 南部县| 曲靖市| 鹤庆县|