lua-users home
lua-l archive

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


On Wed, Oct 27, 2010 at 8:43 PM, Peter <junk_mail@dptr1988.mooo.com> wrote:
> In the lua manual [http://www.lua.org/manual/5.1/manual.html#2.8], it
> makes it look like the __unm metamethod is called with one argument,
> the operand. But it actually appears to be calling the __unm method with
> two arguments, the second being a duplicate of the first argument....I
> noticed it while adjusting the stack top ( with lua_settop ) in a C __unm
> metamethod, but that is probably one of the only situations that it would affect.
> Also the 5.2.0-work4 manual also has this same error.

It does seem odd.  However, in 5.2.0-work4, although the second
argument remains, it is now nil, which also corresponds with
5.2.0-work4 lua_arith in that "When the operation is LUA_OPUNM, the
caller must push a nil value for the second operand."  In 5.2.0-work4,
__len behaves similarly:

_ = # setmetatable({}, {__len = print}) -- prints "table: 0x[...],
nil" in 5.2.0-work4