lua-users home
lua-l archive

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


Mike Pall <mikelu-1107@mike.de> wrote:

> Thomas Lauer wrote:
> > At any rate, I think being able to compare any value against nil
> > without having the comparison itself trigger an error to be an
> > important feature.
> 
> The FFI data types are strictly typed and behave accordingly. In
> fact, it's just a convenience that you can compare them with other
> Lua object types at all. Otherwise all such comparisons would
> return false.
>
> That however implies implicit conversions, e.g. '1LL == 1' is
> really '1LL == ffi.cast("int64_t", 1)'. As with all implicit
> conversions one has to be very careful and very conservative (or
> you end up with something like PHP). That's why 'nil' is turned
> into 'ffi.cast("void *", 0)' and only compares to pointer-like
> objects and nothing else.

Well, I still think that allowing to compare any value (including ffi
values) against the special case of nil would be a sensible thing to do.

I imagine you won't go there so perhaps a hint in the ffi docs (if and
when you find the time) might be a good idea.

> If you really, really need to find out whether something is a nil
> object without ever raising errors, then use 'type(v) == "nil"'.

That's what I've done as a workaround.

-- 
cheers  thomasl