- 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
推薦閱讀
- Learning Microsoft Windows Server 2012 Dynamic Access Control
- 大學計算機應用基礎實踐教程
- Kubernetes實戰
- 計算機圖形學編程(使用OpenGL和C++)(第2版)
- Linux C/C++服務器開發實踐
- Windows Server 2016 Automation with PowerShell Cookbook(Second Edition)
- C語言程序設計同步訓練與上機指導(第三版)
- Access 2010數據庫應用技術(第2版)
- 第一行代碼 C語言(視頻講解版)
- Hadoop 2.X HDFS源碼剖析
- Java Web應用開發給力起飛
- Practical Microservices
- Mastering VMware Horizon 7(Second Edition)
- Microsoft HoloLens By Example
- INSTANT Premium Drupal Themes