LUA Learning Notes (ii)

Source: Internet
Author: User
Tags constructor logical operators lua numeric value

3. Expressions
3.1 Arithmetic Expressions
Binary operator: +-*/^
Unary operator:-(negative value)
3.2 Relational Operators
< > <= >= = = ~=
= = and ~= compare two values, if the two value types are different, LUA considers the two different, nil is only equal to itself.

3.3 logical operators
And Or not
Logical operators believe that false and nil are false, others are true
The operation result of and and or is not true and false, but is related to the numeric value of his two operations.
A and B – if a is false, returns a, otherwise returns B
A or B – if a is true, returns a, otherwise returns B

If x is false or nil assigns an initial value to X
x = x or V
Equivalent to
If not X Then
X =v
End
Three-mesh operator in C language
A?b:c
In Lua
(A and B) or C
The result of not only returns TRUE or False
Not nil–true
Not 2–false
3.4 Join Operators
..

3.5 Priority Level
From high to Low
^
Not-
* /
+ -
..
< > <= >= ~= = =
and
Or
3.6 Structure of the table
The simplest constructor of the table is {}, which is used to create an empty table that can initialize the array directly

A = {x=0, y=0} <–> a = {}; a.x=0; A.y=0
Regardless of how you create the table, we can add or remove any type of field to the table, and the constructor only affects the initialization of the table

Each time the constructor is called, Lua creates a new table that can be constructed using the table list
List = Nil
For the Io.lines () do
List = {next=list, value=line}
End
The following code reads each line from the standard input and then forms the linked list in reverse order

In the same constructor, you can mix the list style and the record style for initialization, such as:

There are limitations to the initialization of the above two constructors, such as you cannot initialize a table with a negative index
element, the string index cannot be properly represented. Here's a more general way to initialize, we use
[expression] Displays the index to which the representation will be initialized:

The style initialization and record style initialization of the list is a special case of this general initialization:
{x=0, y=0} <–> {["X"]=0, ["Y"]=0}
{"Red", "green", "Blue"} <–>{[1]= "Red", [2]= "Green", [3]= "Blue"}
Note: Array subscripts are not recommended starting from 0, otherwise many standard libraries cannot be used.
At the end of the constructor the "," is optional and can be conveniently extended later.
A = {[1]= "red", [2]= "Green", [3]= "Blue",}
In the constructor, the domain delimiter comma (",") can be separated by a semicolon (";"). ) Instead, we usually use semicolons to
Split table elements of different types.
{x=10, y=45; "One", "one", "three"}
Not to be continued ...

Related Article

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.