- Lua Quick Start Guide
- Gabor Szauer
- 135字
- 2021-08-05 10:30:39
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
推薦閱讀
- Mastering Concurrency Programming with Java 8
- DBA攻堅指南:左手Oracle,右手MySQL
- Java EE 6 企業級應用開發教程
- AngularJS深度剖析與最佳實踐
- MATLAB實用教程
- Natural Language Processing with Java and LingPipe Cookbook
- ASP.NET程序開發范例寶典
- Scratch3.0趣味編程動手玩:比賽訓練營
- Java Web應用開發給力起飛
- QlikView Unlocked
- .NET 4.0面向對象編程漫談:應用篇
- 零基礎學Java第2版
- Building UIs with Wijmo
- Building Web and Mobile ArcGIS Server Applications with JavaScript(Second Edition)
- Jenkins 2.x Continuous Integration Cookbook(Third Edition)