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|
1.3 – Some Lexical Conventions
Identifiers in Lua can be any string of letters, digits, and underscores, not beginning with a digit; for instance
i j i10 _ij aSomewhatLongName _INPUTYou should avoid identifiers starting with an underscore followed by one or more uppercase letters (e.g.,
_VERSION); they are reserved for special uses in Lua. Usually, I reserve the identifier
_(a single underscore) for a dummy variable.
In Lua, the concept of what is a letter is locale dependent.
Therefore, with a proper locale, you can use variable names such as
However, such names will make your program unsuitable to run in
systems that do not support that locale.
The following words are reserved; we cannot use them as identifiers:
and break do else elseif end false for function if in local nil not or repeat return then true until whileLua is case-sensitive: and is a reserved word, but
ANDare two other different identifiers.
A comment starts anywhere with a double hyphen (
and runs until the end of the line.
Lua also offers block comments,
which start with
--[[ and run until the corresponding
A common trick,
when we want to comment out a piece of code,
is to write the following:
--[[ print(10) -- no action (comment) --]]Now, if we add a single hyphen to the first line, the code is in again:
---[[ print(10) --> 10 --]]In the first example, the
--in the last line is still inside the block comment. In the second example, the sequence
---[[does not start a block comment; so, the
|Copyright © 2003–2004 Roberto Ierusalimschy. All rights reserved.|