Getting started with LUA programming-learning Note 1

Source: Internet
Author: User

1th Chapter: Starting point

Chunks: statement block

The semicolon at the end of each statement is optional, and if multiple statements on the same line are best separated by semicolons;

Dofile ("Lib1.lua")--Execute LUA file

Global variables: Local variables are modified locally, otherwise global variables

Reserved words:

If then else ElseIf end

And Or not

Fuction return End

True false Nil

While ... do. End break

Repeat ... until ...

For ...-do ... end

Local

Note: Single line--

Multi-line--[[XXX--]

Command line: LUA [option] [script [args]]

-e: Direct incoming commands, such as: Lua-e "Print (Math.sin (12))"

-L: Load files, such as: lua-la-lb, execute A.lua and B.lua files

-I: Interactive mode,

2nd Chapter Types and values

8 Basic types: nil\boolean\number\string\userdata\function\thread\table

Get type by type ()

Escape character: \[\]

3rd Chapter Expressions

Arithmetic operators

Binary operators: +-*/^ (subtraction power)

Unary operators:-

Relational operators

< > <= >= = = ~=

Nil is just the same as himself.

logical operators

And Or not

A? B:c

Join operators

.. -String

Table

{} = days = {"Sunday", "Monday"}

DAYS[1] Index starting from 1!!!

A = {x=0, y=1} <=> a={}; a.x=0; A.y=1 <=> {["X"]=0, ["Y"]=1}

{"Red", "green", "blue"} <=> {[1]= "red", [2]= "Green", [3]= "Blue"}

Array subscripts are not recommended starting from 0, otherwise many standard libraries cannot be used

4th Chapter Basic Grammar

Assignment statement: x, y = y,x

Do ... end <=> C + + {}

Loop statement:

While condition do

Statements

End

Repeat

Statements

until conditions;

For Var=exp1, EXP2, Exp3 do--note: EXP1,EXP2,EXP3 will only be counted once!!!

Loop-part

End

For i,v in Ipairs (a) do print (v) end

5th Chapter function

When calling a function, if the argument list is empty, you must use () to indicate that it is a function call, when the function has only one parameter and the argument is a string or table construct, () is optional.

The matching of LUA function arguments and formal parameters is similar to the assignment statement, the superfluous part is ignored and the missing part is supplemented with nil.

Special function unpack, an array that returns each element of an array as a parameter

Variable parameters: Func (...)

LUA places the variable parameters of the function in a table called ARG, in addition to the parameters, there is a field N in the ARG table that indicates the number of arguments

Dummy variables: _

Local _, X = String.find (s, p)

Named parameters:

Rename (old= "Temp.lua", new= "Temp1.lua")

Getting started with LUA programming-learning Note 1

Related Article

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.