Use the Lua built-in example to learn about Lua 01

Source: Internet
Author: User

-- Example 1 -- first program.

-- Classic hello program.print("hello")-------- Output ------hello

 

-- Example 2 -- Comments.

-- Single line comments in Lua start with double hyphen.--[[ Multiple line comments startwith double hyphen and two square brackets.  and end with two square brackets. ]]-- And of course this example produces no-- output, since it's all comments!-------- Output ------

 

 

-- Example 3 -- variables.

-- Variables hold values which have types, variables don't have types.a=1b="abc"c={}d=printprint(type(a))print(type(b))print(type(c))print(type(d))-------- Output ------numberstringtablefunction

-- Example 4 -- variable names.

-- Variable names consist of letters, digits and underscores.-- They cannot start with a digit.one_two_3 = 123 -- is valid varable name-- 1_two_3 is not a valid variable name.-------- Output ------

 

-- Example 5 -- more variable names.

-- The underscore is typically used to start special values-- like _VERSION in Lua.print(_VERSION)-- So don't use variables that start with _,-- but a single underscore _ is often used as a-- dummy variable.-------- Output ------Lua 5.1

 

 

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.