lua基本语法

1、注释-- ; --[[ ]]

2、控制语句:

if ..then .. elseif.. then.. else.. end

while.. do..end

repeat ..util..

for 1,2,3 do ..end[此处变量,相当于局部变量;可以省略步进值]

3、赋值:a,b,c,d = 1,2,3,4;a,b = b,a

4、字符串连接:"this is".."a string"

5、比较:table function userdata只能 == ~=

6、逻辑运算:and or【x = a?b:c;x = a and b or c;x = x or a】

7、变量类型:nil、boolean、number、string、table、function、userdata、thread

table:t1 = {

  10,

  [100] = 40,

  jone = {haha},

  20

}

注意:可以使用索引,按照1,2先后顺序;可以使用变量名;可以使用字符串

8、function: add = function (a,b) return a + b end