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

  • 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.

主站蜘蛛池模板: 泽州县| 临夏市| 咸阳市| 拉孜县| 即墨市| 体育| 洞口县| 邢台市| 荆州市| 云南省| 高碑店市| 宾阳县| 竹北市| 文水县| 南陵县| 丹江口市| 罗甸县| 白朗县| 苗栗市| 大名县| 阿巴嘎旗| 惠来县| 广安市| 隆尧县| 都江堰市| 延安市| 泾阳县| 重庆市| 眉山市| 珠海市| 当涂县| 长宁区| 九龙城区| 肃北| 玛曲县| 辉县市| 龙江县| 大同市| 腾冲县| 中超| 汶上县|