[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Behavior of lua_arith(L, LUA_OPUNM), arguments to __unm metamethod
- From: Peter Cawley <lua@...>
- Date: Thu, 31 Mar 2011 17:32:14 +0100
On Thu, Mar 31, 2011 at 5:16 PM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
>> In any case it might be nicier to change the interface so
>> that you don't need to push an extra nil (or dummy) value to
>> the stack when using LUA_OPUNM.
>
> This is debatable. It is an inconvenience to push the extra nil
> when using LUA_OPUNM, but it simplifies any code that must handle
> generic arithmetic operations. That is, when 'op' is a constant '_'
> this change is good, but when 'op' is variable it is not so good.
As we've already seen from the internals of lua_arith, the dummy being
nil means that certain classes of generic arithmetic operations cannot
be simplified. From the uses I can think of, unary minus operations
are going to be invoked a lot more often then generic arithmetic
operations are going to be written, so I'd prefer to see the common
case made simpler by removing the dummy.