1.3 – Some Lexical Conventions

#1

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    _INPUT

You 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

índice
or

ação

. 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
   while

Lua is case-sensitive: and is a reserved word, but

And


and

AND


are 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

print

is outside comments. In this case, the last line becomes an independent comment, as it starts with

--
.

Reply




Users browsing this thread:
1 Guest(s)