This first edition was written for Lua 5.0. While still largely relevant for later versions, there are some differences.
The third edition targets Lua 5.2 and is available at Amazon and other bookstores.
By buying the book, you also help to support the Lua project.
|Programming in Lua|
|Part I. The Language Chapter 1. Getting Started|
Global variables do not need declarations. You simply assign a value to a global variable to create it. It is not an error to access a non-initialized variable; you just get the special value nil as the result:
print(b) --> nil b = 10 print(b) --> 10
Usually you do not need to delete global variables; if your variable is going to have a short life, you should use a local variable. But, if you need to delete a global variable, just assign nil to it:
b = nil print(b) --> nilAfter that, it is as if the variable had never been used. In other words, a global variable is existent if (and only if) it has a non-nil value.
|Copyright © 2003–2004 Roberto Ierusalimschy. All rights reserved.|