- 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
推薦閱讀
- Modular Programming with Python
- Python數據分析基礎
- Go語言高效編程:原理、可觀測性與優化
- Android Development with Kotlin
- 網頁設計與制作教程(HTML+CSS+JavaScript)(第2版)
- PostgreSQL 11從入門到精通(視頻教學版)
- Spring實戰(第5版)
- Building a Quadcopter with Arduino
- Python圖形化編程(微課版)
- Node學習指南(第2版)
- Java Web從入門到精通(第2版)
- R語言數據挖掘:實用項目解析
- Learning Concurrency in Python
- Mastering Embedded Linux Programming
- C++標準庫(第2版)