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

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
主站蜘蛛池模板: 怀安县| 尚义县| 乐都县| 山东省| 肃北| 文成县| 沁水县| 建始县| 博乐市| 卢龙县| 吴川市| 前郭尔| 葫芦岛市| 克东县| 老河口市| 双峰县| 会东县| 龙山县| 大城县| 五原县| 宜兴市| 五寨县| 海兴县| 永昌县| 馆陶县| 马山县| 临西县| 潮州市| 宁河县| 许昌县| 满洲里市| 遵义市| 阿尔山市| 东源县| 和龙市| 浮梁县| 桐梓县| 雅江县| 射阳县| 石家庄市| 鄂托克前旗|