print(“hello world”)
–单行注释
–[[
多行注释
变量:字母,数字,下划线, _A @ $ 区分大小写
lua关键字
逻辑运算符:and or not
条件运算符:> < == ~= <= >=
算术运算符:+ - * / %
if…then…else…end if…then…elseif…end
function … end
for…do…end
while…end
repeat…until
in
true false
local nil
i+=1 i++(错误)
]]–
–lua 八大数据类型
–nil boolean number string
–userdata function therad table
–lua所定义的变量默认是全局变量,定义局部变量需要关键字local
–nil:没有任何有效值
–a=nil
print(type(a))
a=1
a=2
print(a)
–用来做删除
a=nil
print(a)
–boolean
–lua把"false"和"nil"认为是false,其他的都为true
print(type(true))
print(type(false))
print(type(nil))
if 0 then
print(“为真”)
end
–number:数字 默认是double类型
print(type(2))
print(type(2.1))
print(type(2.13546489465489415414))
print(type(2e+1))
–string:字符串:由一对双引号或者单引号来表示
string=“abc”
string2=‘abc’
string3=‘a’
print(type(string))
print(type(string2))
print(type(string3))
print(‘2’+6) --8 数字字符串类型自动转换成了数字类型
print(“2”+‘6’) – 8
–print(“error”+2) --报错
print(“error”…2)–字符串拼接
print(#string)–#计算字符串长度
–userdata:用户自定义类型
–将任意c/c++/c#的数据类型存储到lua变量中调用
–thread 线程
–function
–table