The name used in Lua (also known as an identifier) can be any string of letters, numbers, and underscores that do not begin with a number. This conforms to the definition of a name in almost all programming languages. (the definition of a letter depends on the current environment: letters in the alphabet defined in the system environment can be used for identifiers.) Identifier is used to name the variable, or as the name of the table.
The following keyword is reserved and cannot be used as a name:
Copy Code code as follows:
And break do else ElseIf
End False for function if
In the local nil not OR
Repeat return then true until while
Lua is a case-sensitive language: and is a reserved word, but and and and is two different legal names. As a general convention, the names of a string of uppercase letters (such as _version) that begin with an underscore are reserved for the LUA internal global variable.
Here are some of the other token:
Copy Code code as follows:
+–*/% ^ #
= = ~= <= >= < > =
( ) { } [ ]
; : , . .. ...
A string can be either a pair of single quotes or double quotes, which can contain an escape character like C: ' \a ' (bell), ' \b ' (backspace), ' \f ' (form), ' \ n ' (newline), ' \ R ' (carriage return), ' \ t ' (horizontal tabulation), ' \v ' (vertical tabulation), ' \ ' (backslash), ' \ ' (double quotes), and ' \ ' (single quotes). Also, if a backslash is followed by a true newline character, the result is a newline character in the string. We can also describe a character by \ddd the backslash with a digital form. Here, DDD is a string of up to three decimal digits. (Note that if you need a character that is numeric after this description method, then the backslash must be filled with three digits.) The string in Lua can contain any 8-bit value. Including the expression of ' \0′ ' 0.
You must use an escape character only if you need to place different quotes, line breaks, backslashes, or 0 terminator characters into a string. Any other character can be written directly in the text. (Some of the control characters can affect the file system causing some problems, but will not cause any problems with Lua.) )
Strings can also be defined in a way that is enclosed in a long bracket. We have inserted the n equals sign between the two square brackets defined as the nth-level positive long bracket. That is, the 0-level long bracket writing [[, first-level long bracket writing [=[, etc.] The inverse long extension is also defined as a similar definition; for example, the 4-level inverse long bracket writing]====]. A long string can start with a positive long bracket at any level and end with a long bracket that is reversed by the first encountered sibling. The entire lexical parsing process is not subject to branch restrictions, does not process any of the signifier, and ignores any different levels of long braces. The string described in this way can contain anything, except, of course, a specific level of anti-long brackets.
Another convention is that the newline character is not included in the string when a newline character is immediately followed by a positive brace. For example, suppose a system uses ASCII code (at which point the ' a ' code is 97, the line feed is encoded to 10, ' 1′ is encoded as 49), and the following five ways describe the exact same string:
Copy Code code as follows:
A = ' Alo\n123″ '
A = "alo\n123\" "
A = ' \97lo\10\04923″ '
A = [[Alo
123 "]]
A = [==[
Alo
123 "]==]
A numeric constant can be written in two parts, a decimal base portion, and an exponential portion of the decimal point. The exponent portion is optional. Lua also supports hexadecimal integer constants, just preceded by a prefix of 0x. Here are some examples of valid numeric constants:
Copy Code code as follows:
3 3.0 3.1416 314.16e-2 0.31416E1 0xff 0x56
Note You can start with two horizontal (–) anywhere except in the string. If it's not a curly brace, it's a short note, and it's scoped to the end of the line, otherwise it's a long annotation, and it's scoped until it encounters an inverse long bracket. Long annotations are usually used to temporarily block blocks of code.