-- 1.Hello world print( "--------------1--------------") print("Hello world"); -- 2. function define function add(a,b) return a + b end print( "--------------2--------------") print( "enter a number:" ) n = io.read("*number") m = io.read("*number") print( add(m,n) ) -- 3. lua 的数据类型 print( "--------------3--------------") print(type("Hello world")) print(type(2015)) print(type(add)) print(type(false)) print(type(nil)) -- 4. 数字, 字符串操作 print( "--------------4--------------") print( "2015" + 4 + 9) print( "2015" .. 4 .. 9) str = "Hello world" print( """.. str .. "" length: = " .. #str) -- 5. table 关联数组 print( "--------------5--------------") tab1 = {} tab1["day"] = 2015 days = "days" tab1[days] = tab1.day + 1 print(tab1.day) print(tab1.days) -- 用table来实现线性表 array = {}; for i = 1 , 10 do array[i] = i.. " word" end for i = 1, #array do print(array[i]) end -- table大小 print ("the array size: " .. #array) --> the array size: 10 --6. 函数式编程 p = add print( p(2, 3)) --> function programming