[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Operator overloading using tolua++
- From: "Thorsten Scheuermann" <thorsten@...>
- Date: Wed, 1 Feb 2006 11:18:03 -0500
Hi,
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 )
else
return Vec2[".mul"]( lhs, rhs )
end
end
Clearly there's something about how tolua maps __mul to .mul that I
don't entirely understand just yet.
-Thorsten