string1 = "this is string1" string2 = ‘this is string2‘
>也可以用 2 个方括号 "[[]]" 来表示"一块"字符串
html = [[ <html> <head></head> <body> <a href="http://www.baidu.com/">baidu</a> </body> </html> ]]
>在对一个数字字符串上进行算术操作时,Lua 会尝试将这个数字字符串转成一个数字
> print("2" + 6) 8.0 > print("2" + "6") 8.0 > print("2 + 6") 2 + 6
>字符串连接使用的是 ..
> print("a" .. ‘b‘) ab > print(157 .. 428) 157428
>使用 # 来计算字符串的长度,放在字符串前面,如下
> len = "www.baidu.com" > print(#len) 13 > print(#"www.baidu.com") 13
-- 创建一个空的 table local tbl1 = {} -- 直接初始表 local tbl2 = {"apple", "pear", "orange", "grape"}
>table其实是一个"关联数组"(associative arrays),数组的索引可以是数字或者是字符串
不同于其他语言的数组把 0 作为数组的初始索引,在 Lua 里表的默认初始索引一般以 1 开始
-- 访问tbl2的第一个值 > print(tbl2[1]) apple
>table 不会固定长度大小,有新数据添加时 table 长度会自动增长,没初始的 table 都是 nil
原文:http://www.cnblogs.com/jierism/p/6407070.html