lua-users home
lua-l archive

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


On Sun, Sep 14, 2008 at 4:30 PM, Ronald Lamprecht
<R.Lamprecht@t-online.de> wrote:
> 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
>>       error("...")
>>     end
>>   end
>>  end
>
> "h(op)" should result in just one argument on the stack. I am using Lua
> 5.1.2. What is wrong?
>
> Greets,
>
> Ronald

It seems this is a bug to me. __len also has this problem (an extra
nil is pushed on the stack).

-- 
-Patrick Donnelly

"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."

-Will Durant