Lua是动态类型语言,变量没有类型定义,每个变量都可以包含任何类型的值。
Lua的基本类型:boolean、number、string、userdata、function、thread、table
定义几个变量并查看他们的类型,如下:
testBool=true --boolean
testNum=12.3 --number
str="hello world" --string
p=print --print是lua的输出函数
tab={} --定义了一个空得table使用type查看变量的类型:print(type(testBool))
print(type(testNum))
print(type(str))
print(type(p))
print(type(tab))(注:print为lua的输出函数)输出:
boolean
number
string
function
table
本文介绍了Lua作为动态类型语言的特点,通过实例演示了如何定义和操作不同类型的变量,包括布尔型、数值型、字符串型、函数型和表型,并展示了使用type函数检查变量类型的流程。
1万+

被折叠的 条评论
为什么被折叠?



