Lua learning notes --- annotations, variables, strings, and lua learning notes

Source: Internet
Author: User

Lua learning notes --- annotations, variables, strings, and lua learning notes

1. Notes


Single line comment "--" equivalent "//"



Multi-line comment "-- []" is equivalent /**/



Escape nested comments -- [= [] =]


The number of = is not limited, but the number must be equal.


2. Variables


Keyword retention


If

Else

Elseif

Then

End

For

Break

Do

Nil (null)

Local

Function

While

In

And

Or

False

True

Until


Lua variables include global variables and local variables.


All its global variables are stored in a common table,

The advantage of this organizational structure is that, first, there is no need to create a new data structure for global variables, which simplifies the internal implementation of Lua. Another advantage is that, you can operate on this table like other tables. To facilitate this operation, Lua saves the environment table itself in a global variable _ G.

The local declaration is used before the local variable.



Print can be used to display variables, numbers, and strings to terminals.




1> the string format can be single quotation mark ''or double quotation mark" ".



2> escape characters with Backslash "\"




Sometimes a string contains many single or double quotation marks. When using string double quotation marks, use escape characters. If the string content contains many single or double quotation marks, this is very troublesome.

For example, message = "James said," hello ", Li Hong raised his head and said" hello "";

In this case, the [[String] form is used to enclose such strings.




If you are not bothered, you can also use the Escape Character "\"



3> Number







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.