Difference between revisions of "Type"

From GiderosMobile
(added example)
m (Text replacement - "<source" to "<syntaxhighlight")
Line 5: Line 5:
 
=== Description ===
 
=== Description ===
 
Returns the type of its only argument, coded as a string.
 
Returns the type of its only argument, coded as a string.
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
(string) = type(v)
 
(string) = type(v)
 
</source>
 
</source>
Line 27: Line 27:
 
=== Example ===
 
=== Example ===
 
'''Checks if variable x is of type table'''
 
'''Checks if variable x is of type table'''
<source lang="lua">
+
<syntaxhighlight lang="lua">
 
local x = {}
 
local x = {}
 
if type(x) == "table" then print("type is table")
 
if type(x) == "table" then print("type is table")

Revision as of 14:31, 13 July 2023

Available since: Gideros 2011.6
Class: (global)

Description

Returns the type of its only argument, coded as a string. <syntaxhighlight lang="lua"> (string) = type(v) </source>

The possible results of this function are:

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

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 <syntaxhighlight lang="lua"> local x = {} if type(x) == "table" then print("type is table") else print("type is not table") end </source>