lua-users home
lua-l archive

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


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)

work?

Cheers,
Geoff