An expression is considered false, for the purposes of any condition statement, on exactly two conditions: the expression is the boolean value false or the expression is nil.
So if x then foo() end will call foo if x is neither nil nor false. If you want to restrict it to nil only (and you usually don't), then use x ~= nil.
An expression is considered false, for the purposes of any condition statement, on exactly two conditions: the expression is the boolean value
false
or the expression isnil
.So
if x then foo() end
will callfoo
ifx
is neithernil
norfalse
. If you want to restrict it tonil
only (and you usually don't), then usex ~= nil
.