- 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
推薦閱讀
- Java加密與解密的藝術(第2版)
- 區塊鏈:以太坊DApp開發實戰
- Podman實戰
- 深度強化學習算法與實踐:基于PyTorch的實現
- 深入淺出Serverless:技術原理與應用實踐
- 青少年學Python(第1冊)
- 0 bug:C/C++商用工程之道
- Procedural Content Generation for C++ Game Development
- LabVIEW虛擬儀器入門與測控應用100例
- PrimeFaces Blueprints
- Machine Learning for Developers
- 零基礎看圖學ScratchJr:少兒趣味編程(全彩大字版)
- Python趣味創意編程
- Learning RSLogix 5000 Programming
- 瘋狂Java講義精粹