lua-users home
lua-l archive

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

On 10/14/2013 11:25 AM, Carsten Fuchs wrote:
Am 14.10.2013 10:32, schrieb steve donovan:
On Mon, Oct 14, 2013 at 10:23 AM, Thomas Jericke <> wrote:
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.

True, plus making programs even more confusing...

Well, a __tobool metamethod would just be a typecast, like __tostring.

I'm certainly not feverish about this, but for consistency's sake, I think it would be nice to have either -- or none. ;-)

I think the main difference is that string converstions themselves are often not a simple function, so you can easily accept the overhead of a metamethod call. Also in all the programs that are not heavy on text manipulation the __toboolean would be called many more times, just think of all the while and if statements all over the code.

It wouldn't be a perfomance hit if you only use booleans for conditions and logic operations in your code though: if a ~= nil then ... would actuall not trigger the metamethod.