Lua语法

1、Lua保留的关键字:

and,bread,do,else,elseif,end,false,for,function,if,in,local,nil,not,or,repeat,return ,then,true,until,while

2、字符串多行显示

a = [[multiple line
with ‘‘single‘ and "double" quoted strings inside.]]

3、支持同时定义多个变量

a,b,c,d = 1,2,"louis","song";

4、奇葩的交换值

a,b=b,a;
print(a,b);--输出2,1

5、用..连接字符串和数字

a,b = 123,"louisong";
print("a="..a,"b="..louissong);--输出a=123 b="louissong"

6、输出

print "Hello Lua!"
print ("Hello Lua!");

7、标准输入输出,不换行

io.write("hello!")
io.write("hello!")
--output--
hellohello

8、创建表

有点类似as3的Object,创建后可以通过.和[]引用其属性

a = {}
b = {1,2,3}
c = {"a","b"}
a.name = "louissong"
a.adress = "ShangHai"
print(a.name,a["adress"]);

9、if条件语句else

a=1
if a==1 then
    print("a is one")
else
  print("a is not one!");
end

10、多重条件用elseif

Lua语法
if a==1 then
    print("a is 1")
elseif a==2 then
    print(a is 2)
else 
    print(a is 3);
end
Lua语法

Lua语法

上一篇:[itint5]合并K个有序链表


下一篇:对于入门Demo的看法