官术网_书友最值得收藏!

  • Lua Quick Start Guide
  • Gabor Szauer
  • 128字
  • 2021-08-05 10:30:37

Finding a type

There is one very important function built into Lua, type. This function will return the type of a variable as a string. Let's take a look at this function in action:

var1 = true
var2 = 3.145
var3 = nil
var4 = type(var1)
var5 = type(type(var2))

print (type(var1)) -- boolean
print (type(var2)) -- number
print (type(var3)) -- nil
print (var4) -- boolean
print (var5) -- string

Because the type function returns a string, the result can be assigned to a variable, like so:

var4 = type(var1)

Or, the result can be passed directly to a function such as print, like so:

print (type(var1))

The type of the type of something type(type(var2)), as represented by var5, will always be a string. This is because, as stated before, type returns a string.

主站蜘蛛池模板: 绥宁县| 施甸县| 华池县| 驻马店市| 满洲里市| 东方市| 四会市| 通河县| 镇宁| 邵阳市| 镇宁| 信宜市| 长治市| 富源县| 瑞昌市| 井研县| 宜城市| 府谷县| 五家渠市| 龙江县| 龙口市| 定边县| 罗田县| 谷城县| 安吉县| 关岭| 盖州市| 德惠市| 景宁| 六安市| 鄄城县| 徐水县| 定安县| 静海县| 诸城市| 芒康县| 怀宁县| 平塘县| 和平区| 三明市| 通城县|