Difference between revisions of "Type"

From GiderosMobile
 
(3 intermediate revisions by the same user not shown)
Line 19: Line 19:
 
*'''"userdata"'''
 
*'''"userdata"'''
  
In '''Gideros 2024.11'''+ there is this new type:
+
Luau brings in those new types:
*'''color''' (built with the ''ColorValue'' function)
+
*'''"vector"''' (built with the ''vector'' function) since Gideros 2022.1.3
<syntaxhighlight lang="lua">
+
*'''"color"''' (built with the ''ColorValue'' function) since Gideros 2024.11
print(type(ColorValue(1, 0, 1, 1))) -- color
 
print(type(ColorValue)) -- function
 
</syntaxhighlight>
 
  
 
=== Parameters ===
 
=== Parameters ===
Line 39: Line 36:
 
else print("type is not table")
 
else print("type is not table")
 
end
 
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
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
=== See also ===
 
=== See also ===
'''[[Object]]'''
+
'''[[Object]]'''</br>
 +
'''[[vector]]'''</br>
 +
'''[[ColorValue]]'''
  
 
{{(global)}}
 
{{(global)}}

Latest revision as of 03:02, 8 November 2024

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

Parameters

v: (any) value to get type from

Return values

Returns (string) type of the variable

Example

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

See also

Object
vector
ColorValue