Nil
From OpenEUO
Revision as of 19:46, 1 November 2010 by Ximan (Talk | contribs) (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...")
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'