lua-users home
lua-l archive

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


On Mon, Aug 16, 2010 at 11:27 AM, Wesley Smith <wesley.hoke@gmail.com> wrote:
> On Mon, Aug 16, 2010 at 8:17 PM, Peyman <peiman_3009@yahoo.com> wrote:
>>
>> i want create a interpreter based on Lua , but when bodies from other langs come to my interpreter lang say sometimes this default option that 0 and null string have true value bother them because in many langs 0 and null string have false value.
>>
>
> In my experience these other languages are C and C++.  Java requires
> explicit x == null for objets for example.  Ruby is similar to Lua in
> this respect as well.  Basically what I'm getting at is that the
> majority of languages are not this way.  I used to think the same
> thing as you, but in the end my thinking was warped by the all
> pervasiveness of C and C++.
>
> wes
>

In my opinion, the C/C++ behavior is just a side effect of C-strings
being terminated by a null byte, aka 0. Since C didn't have a true
boolean type (correct me if I'm wrong), 0 was used as a false value.
Hence, an empty string is treated as a false value.

It's rather un-obvious in a lot of ways, and I much prefer the
Lua/Ruby semantics. It's abundantly clear what exactly the code
expects.

~Jonathan