Quirrel4.41.0

type

Global, available without an import
pure type(obj): string

Returns the name of obj's type.

Parameters

objanyany value

Return value

One of "null", "bool", "integer", "float", "string", "table", "array", "function", "generator", "userdata", "thread", "class", "instance" or "weakref".

Notes

This is a function, while typeof is an operator: type can be stored in a binding or passed as a callback, and typeof cannot. typeof(v) looks like the same thing written differently, but those parentheses group the operand.

Ignores metamethods, unlike the typeof operator: typeof calls a class's _typeof method when it defines one, so an instance can report any string it likes there, while type() on the same instance always reports the plain "instance". Marked pure because the result depends only on obj.

Example

examples/globals/type.nut
println("type(5) =", type(5))
println("type(\"s\") =", type("s"))
println("type([1]) =", type([1]))
println("type(println) =", type(println))  // a native closure is still "function"

class Custom {
  function _typeof() { return "custom" }  // the `typeof` operator honors this
}
println("type(Custom()) =", type(Custom()))   // type() ignores it: always the raw engine type
println("typeof Custom() =", typeof Custom())  // typeof does not
Output:
type(5) = integer
type("s") = string
type([1]) = array
type(println) = function
type(Custom()) = instance
typeof Custom() = custom

See also

typeofthe type name, through _typeof when there is one
getobjflagsReturns the engine flag bits stored on obj's reference.
globalsmodule index