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

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
主站蜘蛛池模板: 秦皇岛市| 五华县| 余干县| 石阡县| 肥东县| 福安市| 邮箱| 长武县| 肥城市| 葫芦岛市| 门源| 团风县| 饶河县| 当雄县| 正宁县| 方山县| 纳雍县| 元江| 晋州市| 和顺县| 静乐县| 滁州市| 章丘市| 曲阜市| 揭阳市| 揭西县| 边坝县| 璧山县| 中方县| 灌阳县| 塔城市| 崇信县| 连平县| 萍乡市| 河曲县| 五华县| 平遥县| 阳江市| 斗六市| 宾阳县| 财经|