lua-users home
lua-l archive

Re: [Q] newbie questions about timestamp, character code, ..

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Jerome Vuarand wrote:
Gergo Szakal wrote:
if table[key] then ... end
means that if the given key in the table is non-nil, then...
Note that false is a valid table value, and in that case the test above
will fail. To be sure a key is not used check explicitly against nil.
Yes, that's a bad habit from C (or older Lua versions...).
I always test explicitly against nil, even when there is no ambiguity, and use the if foo then only with variables I know being booleans.
Idem in other languages, whatever their tolerance for this idiom.
Just a personal policy, of course.
--
Philippe Lhoste
-- (near) Paris -- France
-- http://Phi.Lho.free.fr
-- -- -- -- -- -- -- -- -- -- -- -- -- --

AltStyle によって変換されたページ (->オリジナル) /