[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: [LuaJIT ffi] Misleading error message?
- From: Mike Pall <mikelu-1107@...>
- Date: Sat, 30 Jul 2011 16:22:38 +0200
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.
If you really, really need to find out whether something is a nil
object without ever raising errors, then use 'type(v) == "nil"'.
--Mike