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

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

主站蜘蛛池模板: 济源市| 彰化市| 秦皇岛市| 东港市| 崇礼县| 会泽县| 双流县| 赤峰市| 扎兰屯市| 伊川县| 七台河市| 广汉市| 平乡县| 福贡县| 阿城市| 龙门县| 黔东| 新田县| 松江区| 宿州市| 深圳市| 万山特区| 平泉县| 广河县| 三河市| 铁岭县| 潜山县| 安阳市| 新余市| 永春县| 南华县| 安康市| 水城县| 三河市| 南江县| 东方市| 株洲市| 鹿邑县| 沙坪坝区| 丹寨县| 竹溪县|