lua-users home
lua-l archive

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

On Wednesday 27 October 2010 7:12:13 pm David Manura wrote:
> 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

Thank you for pointing this out. I hadn't seen the lua_arith function before and the documentation for it helps clarify how these metamethods are called. Apparently part of this issue as already been addressed in 5.2.0-work4 and now it's just a simple matter of making the documentation consistant with itself and the Lua source code.

Short of actually looking at the Lua source code, the "2.4 - Metatables" section the manual seems to be the best way to see the exact details of how the metamethods are handled, which also seems to be supported by the manual itself, given all of the pseudo code and comments in that section for each of the metamethods. So it would be nice if this part of the manual could be as accurate as possible, since the explicit details shown in that section make you think that it's is also precise in the way it describes the metamethod calling conventions.

Also just out of curiosity, what is the reason for using two arguments in a metamethod that only needs one? Or to put it another way: Is there a cool feature that this provides that I'm missing out on? :)