Use the Lua built-in example to learn Lua 03

Source: Internet
Author: User

-- Example 11 -- numbers.

-- Multiple assignment showing different number formats.-- Two dots (..) are used to concatenate strings (or a-- string and a number).a,b,c,d,e = 1, 1.123, 1E9, -123, .0008print("a="..a, "b="..b, "c="..c, "d="..d, "e="..e) -------- Output ------a=1 b=1.123 c=1000000000 d=-123 e=0.0008

-- Example 12 -- more output.

-- More writing output.print "Hello from Lua!"print("Hello from Lua!") -------- Output ------Hello from Lua!Hello from Lua!

-- Example 13 -- more output.

-- io.write writes to stdout but without new line.io.write("Hello from Lua!")io.write("Hello from Lua!")-- Use an empty print to write a single new line.print() -------- Output ------Hello from Lua!Hello from Lua!

-- Example 14 -- tables.

-- Simple table creation.a={} -- {} creates an empty tableb={1,2,3} -- creates a table containing numbers 1,2,3c={"a","b","c"} -- creates a table containing strings a,b,cprint(a,b,c) -- tables don't print directly, we'll get back to this!!-------- Output ------table: 001EC6D0 table: 001EC7E8 table: 001EC860

-- Example 15 -- more tables.

-- Associate index style.address={} -- empty addressaddress.Street="Wyman Street"address.StreetNumber=360address.AptNumber="2a"address.City="Watertown"address.State="Vermont"address.Country="USA"print(address.StreetNumber, address["AptNumber"]) -------- Output ------360 2a

 

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.