Re: [Q] newbie questions about timestamp, character code, ..
[
Date Prev][
Date Next][
Thread Prev][
Thread Next]
[
Date Index]
[
Thread Index]
- Subject: Re: [Q] newbie questions about timestamp, character code, ..
- From: Philippe Lhoste <PhiLho@...>
- Date: 2007年2月09日 15:53:24 +0100
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
-- -- -- -- -- -- -- -- -- -- -- -- -- --