lua-users home
lua-l archive

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

> -----Original Message-----
> From:
> []On Behalf Of Roberto
> Ierusalimschy
> Sent: Wednesday, March 24, 2004 7:29 AM
> To: Lua list
> Subject: Re: Why no metamethods for logical operators? 
> > I understand that there may be some complications because 
> of short-cut
> > evaluation, but it seems that this could be handled similar to C++
> > (i.e. just eliminate short-cut evaluation in overloading 
> situations).
> > [...] In any case does anyone know if there is a chance this feature
> > might be added in the future?
> There are some problems. First, those operators already have a clear
> meaning for all values in Lua. Second, unlike C++, Lua would have to
> decide on runtime whether it should use short-cut evaluation or not.
> This does not seem very good for the precompiler. So, unless someone
> can show a simple, small, and efficient implementation, we are not
> considering this feature.

I believe C++ must also decide at runtime. Couldn't Lua just ignore
operand values when executing overloaded "and" and "or"? In any case 
you know the code so I should probably defer to your judgment on this.
I might take a look at the code if that's Ok, just to see if I can
think of a good solution. I'm reasonably experienced in implementing

> > I am working on layout processing software and I find it 
> would be useful
> > to overload these operators in order to specify design rules.
> Have you exhausted the other six operators? (+ - * / .. ^)

I need the (+ - * /) operators for similar things to what they do now. 
The (.. ^) operators are a possibility but their precedence makes them
problematic. Another possibility would be a generic user definable 
operator such as ~operator_name~. I could then write something like
"e1.x - e2.x < 50 ~or~ e1.x - e2.x > 200". I realize this is probably
a major change. I'm just thinking out loud. 

In any case I really like Lua. I downloaded it about a year ago and 
started incorporating it into new tools. I initially got a bit of 
flack for introducing a new language into our department. However it
worked so well that everyone seems to be happy now.