lua-users home
lua-l archive

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

Hi all,

In the original Lua, 0 was logically true, because the only logically false
value was nil. That made sense. But since the introduction of the boolean
type in Lua 5, there is a slight mess in what is actually logically false, causing me to reconsider on the idea of 0 being logically true.

Both nil and false are logically false now. But they are different, i.e
false~=nil . This is a bit awkward because you can't be sure about what does
"if foo then..." mean. Furthermore, this:

if tab[key] then
 print "key exists in the table"
 print "key does not exist in the table"

does not work any more, because tab[key] could exist, yet hold the value of
false. So you _have_ to write it like "if tab[key]~=nil then..."

With the current behavior, this convenience is non existant, so I fail to
see what is the reasoning behind 0 still being true? Since there are already
two different values of logical false, why not add two more and have 0 and
"" logically false as well?

For interfacing with C programs, and for general convenience of the
scripting user, we are considering patching the lua in our app, to have zero
and empty string mean the same thing (logically) as false as nil currently
do. Does anyone see why would that be a bad idea?