lua-users home
lua-l archive

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


>> How about a metamethod __tobool ?
>>
>> Then everyone could define him- or herself if and how any Lua type should
>> evaluate to bool in a boolean expression.  :-)

> I think it could be a to high performance hit to have a metamethod lookup on
> each and every condition or logical expression of a program.

The Lua principle is "whoever needs something special must take the
performance hit". So instead of a metamethod, use a function 'tobool' to
explicitly cast whatever you need only when you need it. That function
could check for the availability of __tobool in the metatable. If the
performance hit is found to be substantial, coding tobool in C might
help.