Lua Study Notes 11: Tips in lua, lua Study Notes
The tips in lua are the special features of the basic lua language.
Clever Use or
x = x or v
It is equivalent:
if not x then x = vend
If x is nil or false, assign it a value
Binary ternary operator implementation
a and b or c
Similar to C language:
a ? b : c
The and operation takes precedence over or.
Fill in 0 for the third digit
str = string.format("%02d",num)
Equivalent
if num < 10 then str = string.format("0%d", num)else str = string.format("%d", num)end
This expression is often used to get regular image names, time conversion, etc.
Assignment Problem and type method in lua
The print (123) function is used to output information to the standard. Print does not return values.
So your a = print (123)
No effect on. It still does not exist. Read any nonexistent variable to obtain nil.
If the type parameter is nil, nil is returned. So type (a) = type (nil) = nil
Degrees for type (a) will return nil, nil is lua built-in type, indicating that the value does not exist.
How LUA cainiao installed LUA
In windows, you don't have to worry about using the compiled installation package:
Luaforge.net/frs /? Group_id = 377