lua-users home
lua-l archive

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


On 13.01.2011 15:51, Tony Finch wrote:
> On Wed, 12 Jan 2011, David Manura wrote:
>>
>> Even `1LL == 1` may not be so clear.  In code like `if b == 1 then
>> [...] end` written only with standard Lua in mind, it can be assumed b
>> is 1 inside the block, or at least that b has all the properties that
>> 1 has.  It's conceivable (however remotely) that this code may break
>> under the above proposal if 1LL somehow makes it into b.
> 
> It is in fact quite likely if b is used to index a table, if I understand
> Mike's description correctly.
> 
> If FFI objects are necessarily boxed, it seems to me reasonable to require
> some kind of explicit conversion from a cdata ((long) long) int to a Lua
> number, such as `if b.n == 1 then ...`.

I agree, but would suggest:
if tonumber(b) ==1 then...
or
if tostring(b) =="1" then...

and forbid to use comparisons (so tonumber()/tostring() would be the
only interface between number and ffi type objects. This seems easier to
read and lowers the risk of misusing comparisons.

Regards,
miko