Lua tutorial-Basics

Source: Internet
Author: User

1. Keyword

And

Break

Do

Else

Elseif

 

End

False

For

Function

If

 

In

Local

Nil

Not

Or

 

Repeat

Return

Then

True

Until

While

2. Data Type

How can we determine the type of a variable? You can use the type () function to check. Lua supports the following types:

Nil

Null Value. All unused variables are nil. Nil is both a value and a type.

Boolean

Boolean value. There are only two valid values: true and false.

Number

Numeric value. In Lua, the value is equivalent to double in C.

String

String. If you want to, the string can contain the "\ 0" character (which is different from the C language that always ends with "\ 0)

Table

Link Table type. This type is powerful. For more information, see the following section.

Function

Function type. Do not doubt that a function is also a type. That is to say, all functions are a variable.

Userdata

Well, this type is used to deal with Lua's host. Generally, the host is written in C and C ++. In this case, userdata can be any data type of the host, usually including struct and pointer.

Thread

Thread type. There is no real thread in Lua. In Lua, a function can be divided into several parts for running. If you are interested, you can go to Lua's documents.
Now let's look back at it. I don't think it's a thread type. Instead, the iterator function is used for traversal.
For example:

Function range (N)
Local I = 0
While (I <n) Do
Coroutine. Yield (I)
I = I + 1
End
End

Unfortunately, you need the coroutine. Resume function to continue running. Please advise.

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.