- 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.
推薦閱讀
- Dynamics 365 for Finance and Operations Development Cookbook(Fourth Edition)
- Monkey Game Development:Beginner's Guide
- 摩登創(chuàng)客:與智能手機和平板電腦共舞
- Rake Task Management Essentials
- Offer來了:Java面試核心知識點精講(原理篇)
- Web Application Development with R Using Shiny(Second Edition)
- PostgreSQL 11從入門到精通(視頻教學版)
- Spring Boot Cookbook
- Java EE核心技術與應用
- Visual FoxPro程序設計習題集及實驗指導(第四版)
- Natural Language Processing with Java and LingPipe Cookbook
- Building Machine Learning Systems with Python(Second Edition)
- 快速入門與進階:Creo 4·0全實例精講
- 深入理解BootLoader
- 超簡單:用Python讓Excel飛起來(實戰(zhàn)150例)