lua-users home
lua-l archive

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


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