[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: Roberto Ierusalimschy <roberto@...>
- Date: Thu, 31 Mar 2011 13:16:25 -0300
> I think I have discovered a bug in Lua 5.2 alpha:
>
> [...]
>
> I can get it to work, when I push a second dummy number
> instead of nil, but that's not what the specification
> requests:
> http://www.lua.org/work/doc/manual.html#lua_arith
Many thanks for the report.
> 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.
> Another issue related to unary minus is the following:
>
> [...]
>
> The documentation of both Lua 5.1 and Lua 5.2 alpha imply
> that there would only be one argument passed to the
> metamethod. The implementation in Lua 5.2 alpha is closer to
> the documentation but not yet exactly matching.
Before the code, the 5.2 manual says this:
For the unary '-' and '#' operators, the metamethod is called with
a dummy second argument. This extra argument is only to simplify
Lua's internals; it may be removed in future versions and therefore
it is not present in the following code. (For most uses this extra
argument is irrelevant.)
-- Roberto