Difference between revisions of "Type values"

From OpenEUO
Jump to: navigation, search
m
m
 
Line 17: Line 17:
 
  --> 'number'
 
  --> 'number'
 
  --> 'boolean'
 
  --> 'boolean'
 +
 +
Lua doesn't distinguish between integer and floating point numeric types-- both are stored as floating point numbers.  This only makes a difference for mathematical operations involving or resulting in ''very'' large integers (15 decimal digit precision).  Also, care should be taken when discriminating between boolean [[false]] and the value [[nil]].
  
 
== See Also ==
 
== See Also ==
Line 22: Line 24:
 
* [[false]]
 
* [[false]]
  
* [[true]]
+
* [[math.huge]]
  
 
* [[nil]]
 
* [[nil]]
 +
 +
* [[true]]
  
 
* [[type]]
 
* [[type]]

Latest revision as of 23:44, 1 November 2010

The lua type() function has fixed strings that it returns depending upon the type of value represented by its argument. These constant strings are 'boolean', 'function', 'nil', 'number', 'string', 'table' (and not commonly seen in openeuo, 'userdata' and 'thread').

print(type(print))
print(type('A'))
print(type(1))
print(type({}))
print(type(nil))
local b = 6
print(type(b))
print(type(false))
--> 'function'
--> 'string'
--> 'number'
--> 'table'
--> 'nil'
--> 'number'
--> 'boolean'

Lua doesn't distinguish between integer and floating point numeric types-- both are stored as floating point numbers. This only makes a difference for mathematical operations involving or resulting in very large integers (15 decimal digit precision). Also, care should be taken when discriminating between boolean false and the value nil.

See Also