Difference between revisions of "Type"
From GiderosMobile
(added example) |
|||
(5 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. | |
<source lang="lua"> | <source lang="lua"> | ||
(string) = type(v) | (string) = type(v) | ||
</source> | </source> | ||
+ | |||
+ | The possible results of this function are: | ||
+ | *'''"nil"''' (a string, not the value nil) | ||
+ | *'''"number"''' | ||
+ | *'''"string"''' | ||
+ | *'''"boolean"''' | ||
+ | *'''"table"''' | ||
+ | *'''"function"''' | ||
+ | *'''"thread"''' | ||
+ | *'''"userdata"''' | ||
+ | |||
=== Parameters === | === Parameters === | ||
− | '''v''': (any) | + | '''v''': (any) value to get type from<br/> |
+ | |||
=== Return values === | === Return values === | ||
− | '''Returns''' (string) | + | '''Returns''' (string) type of the variable<br/> |
+ | |||
+ | === Example === | ||
+ | '''Checks if variable x is of type table''' | ||
+ | <source lang="lua"> | ||
+ | local x = {} | ||
+ | if type(x) == "table" then print("type is table") | ||
+ | else print("type is not table") | ||
+ | end | ||
+ | </source> | ||
+ | |||
+ | {{(global)}} |
Revision as of 20:28, 4 March 2021
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"
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