Variable types and how to check them

From ESOUI Wiki

Jump to: navigation, search

Contents

Basic Types

nil
NIL value
boolean
True or False
number
string
userdata
function
Yes, your function is a variable
thread
table
userdata

Checking Type

type(var)

Example

local boolvar = true
local numvar = 27
local stringvar = "This is text"
local function funcvar() end
local tablevar = {2, 4, 6}
 
d(type(var)) -- outputs "nil" because var has not been initialized with any value yet
var = 16
d(type(var)) -- outputs "number"
 
d(type(boolvar)) -- outputs "boolean"
d(type(numvar)) -- outputs "number"
d(type(stringvar)) -- outputs "string"
d(type(funcvar)) -- outputs "function"
d(type(tablevar)) -- outputs "table"
 
if type(boolvar) == "boolean" then d("do stuff") end
if type(numvar) == "number" then d("we can do number stuff") else d("This is not a number") end
if type(stringvar) != "string" then d("Type mismatch error.  String requried.") end
if type(funcvar) == "function" then d("Type: Function") end
if type(tablevar) == "table" then d("Table is: ") d(tablevar) end

External Links

Personal tools
Namespaces
Variants
Actions
Menu
Wiki
Toolbox