lua-users home
lua-l archive

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


Thanks all,

* I'm trying luafilesystem
* I use 'string.byte("x")'
* It is not able to set nil into table as 'valid' value. It is a rule of Lua.

I appreciate your helps.

--
regards,
kwatch


On 2/9/07, Philippe Lhoste <PhiLho@gmx.net> wrote:
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
--  --  --  --  --  --  --  --  --  --  --  --  --  --