type
Global, available without an import
Returns the name of obj's type.
Parameters
obj | any | any 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
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 notOutput:
type(5) = integer
type("s") = string
type([1]) = array
type(println) = function
type(Custom()) = instance
typeof Custom() = customSee also
typeof | the type name, through _typeof when there is one |
getobjflags | Returns the engine flag bits stored on obj's reference. |
| globals | module index |