[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Metamethod "unm" call stack
- From: "Patrick Donnelly" <batrick.donnelly@...>
- Date: Sun, 14 Sep 2008 16:53:07 -0600
On Sun, Sep 14, 2008 at 4:30 PM, Ronald Lamprecht
> On implementation of a unary minus method for an own userdata object I
> noticed that lua_gettop(L) returns the value 2. I expected a value of 1,
> just the object itself. The refman states that the calling code is
> equivalent to:
>> function unm_event (op)
>> local o = tonumber(op)
>> if o then -- operand is numeric?
>> return -o -- `-' here is the primitive `unm'
>> else -- the operand is not numeric.
>> -- Try to get a handler from the operand
>> local h = metatable(op).__unm
>> if h then
>> -- call the handler with the operand
>> return h(op)
>> else -- no handler available: default behavior
> "h(op)" should result in just one argument on the stack. I am using Lua
> 5.1.2. What is wrong?
It seems this is a bug to me. __len also has this problem (an extra
nil is pushed on the stack).
"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."