Lua Study Notes 11: Tips in lua, lua Study Notes

Source: Internet
Author: User

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

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.