lua-users home
lua-l archive

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


On Mon, Sep 15, 2008 at 2:30 AM, 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?

I think this post is related to the question:

http://lua-users.org/lists/lua-l/2007-07/msg00587.html

HTH,
Alexander.