lua-users home
lua-l archive

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

Justin Cormack <> wrote:

> On Sat, 2011-07-30 at 16:04 +0100, Thomas Lauer wrote:
> > 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.
> > 
> Usually you can just test with 'if not v then ...' rather than if v ==
> nil then ...', so actually comparing to nil is rarely needed, unless
> false is a sane value...

Sure, that's what I'd usually do... but in this specific case false is a
rare but quite feasible value for v. In fact, v could have *any*
possible type and value and I have no control over what this might be.

Anyway, I first did

> if type(v)~=='nil' then ...

but now I'm doing

> if v or v==false then ...

as this should generally be slightly faster.

cheers  thomasl