lua-users home
lua-l archive

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


   I'm replying to myself with a solution to my problem. Maybe someone
finds it interesting. 
> My attempt at a workaround was this:
> Vec2[".mul_orig"] = Vec2[".mul"]          -- save tolua-generated mul
> operator
> Vec2[".mul"] = function( lhs, rhs )       -- .mul is called 
> from Vec2's
> __mul metamethod
>   if type( lhs ) == "number" then
>     return Vec2[".mul_orig"]( rhs, lhs )  -- switch operand order and
> call original mul
>   else
>     return Vec2[".mul_orig"]( lhs, rhs )
>   end
> end

It turns out the solution is to redefine the __mul metamethod directly
instead of tolua's .mul function:

Function Vec2.__mul( lhs, rhs )
  if type( lhs ) == "number" then
    return Vec2[".mul"]( rhs, lhs )
    return Vec2[".mul"]( lhs, rhs )

Clearly there's something about how tolua maps __mul to .mul that I
don't entirely understand just yet.