Lua 中有 8 个基本类型分别为:nil、boolean、number、string、userdata、function、thread 和 table。
| 数据类型 |
描述 |
| nil |
表示一个无效值(在条件表达式中相当于false) |
| boolean |
包含两个值:false和true。 |
| number |
表示双精度类型的实浮点数 |
| string |
字符串由一对双引号或单引号来表示 |
| function |
由 C 或 Lua 编写的函数 |
| userdata |
表示任意存储在变量中的C数据结构 |
| thread |
表示执行的独立线路,用于执行协同程序 |
| table |
Lua 中的表(table)其实是一个”关联数组”(associative arrays),数组的索引可以是数字、字符串或表类型。 |
print(type("Hello world")) --> stringprint(type(10.4*3)) --> numberprint(type(print)) --> functionprint(type(type)) --> functionprint(type(true)) --> booleanprint(type(nil)) --> nilprint(type(type(X))) --> string