Skip to Content
Lua Quick Start Guide
book

Lua Quick Start Guide

by Gabor Szauer
July 2018
Beginner
202 pages
5h 42m
English
Packt Publishing
Content preview from Lua Quick Start Guide

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 = truevar2 = 3.145var3 = nilvar4 = type(var1)var5 = type(type(var2))print (type(var1)) -- booleanprint (type(var2)) -- numberprint (type(var3)) -- nilprint (var4) -- booleanprint (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. ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Beginning Lua Programming

Beginning Lua Programming

Kurt Jung, Aaron Brown
Vim Masterclass

Vim Masterclass

Jason Cannon

Publisher Resources

ISBN: 9781789343229Supplemental Content