Lua的类型和值

 Lua是一种动态类型的语言,变量不需要做定义。Lua中有八种类型,分别是

nil                 --
boolean            -- 布尔
number             -- 数字
string              -- 字符串
userdata            -- 自定义
function            -- 函数
thread              -- 线程
table               --

 

用type()识别变量的类型

str="我是中国人"
ty=type(str)
print(ty)    --string


str=10
ty=type(str)
print(ty)   --number


ty=type(b)
print(ty)    --nil


--[[
布尔类型:
两个取值 false 和true。
但要注意Lua中所有的值都可以作为条件。
在控制结构的条件中除了false和nil为假,其他值都为真。所以Lua认为0和空串都是真。
    ]]

a=10
b=a==10
print(b)    --true

 

 

 

 

 

 

 

 

 

 

 

posted @ 2025-03-04 07:16  天子骄龙  阅读(17)  评论(0)    收藏  举报