-- 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())
print(type(add))
print(type(false))
print(type(nil)) -- 4. 数字, 字符串操作
print( "--------------4--------------")
print( "" + + )
print( "" .. .. ) str = "Hello world"
print( "\"".. str .. "\" length: = " .. #str) -- 5. table 关联数组
print( "--------------5--------------")
tab1 = {}
tab1["day"] =
days = "days"
tab1[days] = tab1.day + print(tab1.day)
print(tab1.days) -- 用table来实现线性表
array = {};
for i = , do
array[i] = i.. " word"
end for i = , #array do
print(array[i])
end -- table大小
print ("the array size: " .. #array) --> the array size: 10 --6. 函数式编程
p = add
print( p(, )) --> function programming
05-11 09:42