lua-users home
lua-l archive

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


On Mon, Jul 31, 2000 at 07:06:27PM -0300, Steve Dekorte wrote:
> David Jeske <jeske@chat.net> wrote:
> > Solutions that seem useful to me would be:
> >  - allowing "0" to be considered false 
> >  - creating a "real false" value, which looks like nil, but takes
> >    up space.
> 
> How about a tagmethod for boolean:

That would also work well. :)

> ----------
> None = {}
> 
> noneTag = newtag()
> settagmethod( noneTag, "boolean", function () return nil end)
> settag(None, noneTag)
> ----------
> 
> Now when we have:
> 
> if aTable.a then
>   ...
> end
> 
> If "a" is None or nil, then the "if" evaluates a false
> otherwise it evaluates to true. "None" could then be used
> as the false boolean (unlike nil) can hold a place in a table.


-- 
David Jeske (N9LCA) + http://www.chat.net/~jeske/ + jeske@chat.net