Difference between revisions of "Nil"
From OpenEUO
					
										
					
					m (Created page with "nil is a lua keyword and valid value and specifies something that does not exist.    local a = 1   a = a + b    --> 'Error: attempt to perform arithmetic on global 'b' (a nil val...")  | 
				m  | 
				||
| Line 15: | Line 15: | ||
If a function call returns no results and yet it is assigned to a variable, that variable is still [[nil]].  If a function returns fewer results than available assignment variables, the extra variables are set to nil.  | If a function call returns no results and yet it is assigned to a variable, that variable is still [[nil]].  If a function returns fewer results than available assignment variables, the extra variables are set to nil.  | ||
| − | local f     = function() return 1,2 end  | + |  local f     = function() return 1,2 end  | 
| − | + |  local a,b,c = 1,1,1  | |
| − | + |  a,b,c = f()  | |
| − | + |  print(type(c))  | |
| − | + |  --> 'nil'  | |
Revision as of 18:46, 1 November 2010
nil is a lua keyword and valid value and specifies something that does not exist.
local a = 1 a = a + b
--> 'Error: attempt to perform arithmetic on global 'b' (a nil value)'
If no value has been assigned to a variable, then it is of type 'nil'.
local a print(type(a))
--> 'nil'
If a function call returns no results and yet it is assigned to a variable, that variable is still nil. If a function returns fewer results than available assignment variables, the extra variables are set to nil.
local f = function() return 1,2 end local a,b,c = 1,1,1 a,b,c = f() print(type(c))
--> 'nil'