Type: Difference between revisions

From GiderosMobile
No edit summary
No edit summary
 
(20 intermediate revisions by 2 users not shown)
Line 1: Line 1:
__NOTOC__
__NOTOC__
'''Available since:''' Gideros 2011.6<br/>
'''Available since:''' Gideros 2011.6<br/>
'''Class:''' [[(global)]]<br/>
=== Description ===
=== Description ===
Returns the type of its only argument, coded as a string. The possible results of this function are "nil" (a string, not the value nil), "number", "string", "boolean", "table", "function", "thread", and "userdata".
Returns the type of its only argument, coded as a string.
<source lang="lua">
<syntaxhighlight lang="lua">
(string) = type(v)
(string) = type(v)
</source>
</syntaxhighlight>
'''v''': (any) value to get type from ''''''<br/>
 
The possible results of this function are:
*'''"nil"''' (a string, not the value nil)
*'''"number"'''
*'''"string"'''
*'''"boolean"'''
*'''"table"'''
*'''"function"'''
*'''"thread"'''
*'''"userdata"'''
 
Luau brings in those new types:
*'''"vector"''' (built with the ''vector'' function) since ''Gideros 2022.1.3''
*'''"color"''' (built with the ''ColorValue'' function) since ''Gideros 2024.11''
*'''"buffer"''' (built with the ''buffer'' table) since ''Gideros 2025.1''
 
=== Parameters ===
'''v''': (any) value to get type from<br/>
 
=== Return values ===
'''Returns''' (string) type of the variable<br/>
'''Returns''' (string) type of the variable<br/>
=== Examples ===
'''Checks if variable x is of type table'''
<syntaxhighlight lang="lua">
local x = {}
if type(x) == "table" then print("type is table")
else print("type is not table")
end
</syntaxhighlight>
'''New Luau types'''
<syntaxhighlight lang="lua">
print(type(vector(64, 38, 16))) -- vector
print(type(vector)) -- function
print(type(ColorValue(1, 0, 1, 1))) -- color
print(type(ColorValue)) -- function
print(type(buffer.create(16))) -- buffer
print(type(buffer)) -- table
</syntaxhighlight>
=== See also ===
'''https://luau.org/library#global-functions'''<br/>
'''[[typeof]]'''</br>
'''[[Object]]'''</br>
'''[[vector]]'''</br>
'''[[ColorValue]]'''</br>
'''[[buffer_luau]]'''
{{(global)}}

Latest revision as of 10:27, 21 July 2025

Available since: Gideros 2011.6
Class: (global)

Description

Returns the type of its only argument, coded as a string.

(string) = type(v)

The possible results of this function are:

  • "nil" (a string, not the value nil)
  • "number"
  • "string"
  • "boolean"
  • "table"
  • "function"
  • "thread"
  • "userdata"

Luau brings in those new types:

  • "vector" (built with the vector function) since Gideros 2022.1.3
  • "color" (built with the ColorValue function) since Gideros 2024.11
  • "buffer" (built with the buffer table) since Gideros 2025.1

Parameters

v: (any) value to get type from

Return values

Returns (string) type of the variable

Examples

Checks if variable x is of type table

local x = {}
if type(x) == "table" then print("type is table")
else print("type is not table")
end

New Luau types

print(type(vector(64, 38, 16))) -- vector
print(type(vector)) -- function

print(type(ColorValue(1, 0, 1, 1))) -- color
print(type(ColorValue)) -- function

print(type(buffer.create(16))) -- buffer
print(type(buffer)) -- table

See also

https://luau.org/library#global-functions
typeof
Object
vector
ColorValue
buffer_luau