[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: __mul()
- From: Geoff Leyland <geoff_leyland@...>
- Date: Sun, 21 Mar 2010 15:26:18 +1300
On 21/03/2010, at 3:21 PM, Christopher Eykamp wrote:
> On 3/20/2010 7:08 PM, Geoff Leyland wrote:
>> On 21/03/2010, at 3:04 PM, Christopher Eykamp wrote:
>>> If this works:
>>> newpt = bot:getLoc():__mul(2)
>>> Shouldn't this:
>>> newpt = bot:getLoc() * 2
>>> Instead I get an error: "attempt to perform arithmetic on a userdata value."
>>> Some quick background: bot:getLoc() is a C++ method that returns a pointer to a point stored in C++. I am binding Lua and C++ using Lunar. __mul() is a method added in Lua (I have also tried adding it via C++). How can I get arithmetic methods to work on userdata?
>>> Any ideas?
>> I know nothing about Lunar, but does
>> newpt = getmetatable(bot:getLoc()):__mul(2)
> Curiously, no, though it does get to the __mul() function before giving me this error:
> "calling 'getxy' on bad self (Point expected, got table)."
Sorry! That was my mistake. Clearly (when I look again) the metatable (not a point userdata) is passed as the first argument.
> So it's able to find the function properly, but in this case, it seems to get confused as to what the self object is.
> This, however, does work:
> newpt = getmetatable(bot:getLoc()).__mul(bot:getLoc(), 2)
So I guess this means that I don't have any idea. Are there restrictions on mixed types for operators with userdata?