This blog learns about the LUA operator, which is simpler, and I write the instructions directly to the code, as follows.
--Arithmetic operator--two-dollar operator: +-*/^ (subtraction power)--Unary operator:-(negative)-the operands of these operators are real numbers, and there are no self-decrement operators in Lua. --Relational operator--< > <= >= = = ~=--Here's what you need to be aware of, which is not represented by ~=--these operators return the results to false or true;== and ~= compare two values, and Lua thinks they are different if two value types are different;- The-nil is only equal to himself. Lua compares tables, UserData, and functions by reference.
That is, it is equal if and only if both represent the same object. --lua Compare numbers by traditional numeric size, comparing strings in alphabetical order, print ("0" = 0)--false A = {1,2} b = {1,2} c = a print (a==c)-->true print (a==b) -->false Print (2 <)--True Print ("2" < ")--false--logical operator--and or not--logical operators think false and nil are false (false)
, the other is true, and 0 is true.
The--and and OR operation results are not true and false, but are related to its two operands.
--a and B Returns a If a is false, otherwise returns B--a or B if A is true, returns a, otherwise returns B print (false)--> false print (4 or 5)--> 4 Print (False or 5)--> 5-A useful technique: ternary operator A in C language? B:C can be implemented in LUA: (A and B) or C local A = 1 Local b = 2 Local num = (a>b and a) or B print (num)-->2--concatenation operator--.. Two points-string concatenation, and Lua converts numbers to strings if operands are numbers. Notice the space between the numbers print ("Hello" ...).
Lua ")--> Hello Lua print (0.. 1)--> 01
Finally explain the precedence of operators, give you a table for reference, use the time to check.