I 'm not sure is it ok to use if x then foo() end to detect x is not nil in Lua.
There's so many detect like this in the project at hand, so I need a suggestion should I change them all or let them go.
Thanks.
I 'm not sure is it ok to use if x then foo() end to detect x is not nil in Lua.
There's so many detect like this in the project at hand, so I need a suggestion should I change them all or let them go.
Thanks.
Copyright © 2021 Jogjafile Inc.
An expression is considered false, for the purposes of any condition statement, on exactly two conditions: the expression is the boolean value
falseor the expression isnil.So
if x then foo() endwill callfooifxis neithernilnorfalse. If you want to restrict it tonilonly (and you usually don't), then usex ~= nil.