-- 获取字符串长度 str = "this is a test." print(type(str))
1 2
local x = 10-- 局部变量 x = 10-- 全局变量
1 2 3 4 5 6 7 8 9 10 11
-- lua中的函数可以当作变量 functionfactorial1(n) if n == 0then return0 else return n * factorial1(n - 1) end end print(factorial1(10)) factorial2 = factorial1; print(factorial2(10))
1 2
-- if ip is true return ip, if ip is nil return "unknow" return ip or unknow