Global/tobool

From Garry's Mod
(Difference between revisions)
Jump to: navigation, search
m
 
Line 1: Line 1:
 
{{Func
 
{{Func
 +
|Name=tobool
 +
|Parent=Global
 
|Description=Attempts to return an appropriate boolean for the given value
 
|Description=Attempts to return an appropriate boolean for the given value
 
|Realm=Shared and Menu
 
|Realm=Shared and Menu
 
|IsClass=No
 
|IsClass=No
 
|File=lua/includes/util.lua
 
|File=lua/includes/util.lua
|Line=244-L244
+
|Line=248-L251
|Name=tobool
+
|Parent=Global
+
 
}}
 
}}
 
{{Arg
 
{{Arg

Latest revision as of 21:38, 21 February 2019

 tobool( )

Contents

Description

Attempts to return an appropriate boolean for the given value

Arguments

any val

The object to be converted to a boolean

Returns

boolean

false for the boolean false.
false for "false".
false for "0".
false for numeric 0.
false for nil.

true otherwise.

Examples

Example

Demonstrate the output of this function with various values.

print("boolean true:", tobool(true))
print("boolean false:", tobool(false))
print("string true:", tobool("true"))
print("string false:", tobool("false"))
print("numeric 0:", tobool(0))
print("string 0:", tobool("0"))
print("string 1:", tobool("1"))
print("nil:", tobool(nil))
print("text string:", tobool("not a boolean"))
print("empty string:", tobool(""))

Output:

boolean true: true boolean false: false string true: true string false: false numeric 0: false string 0: false string 1: true nil: false text string: true empty string: true
Personal tools
Navigation