lua-users home
lua-l archive

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

On 3/20/2010 7:10 PM, Jonathan Castello wrote:
On Sat, Mar 20, 2010 at 7:04 PM, Christopher Eykamp<>  wrote:
If this works:

   newpt = bot:getLoc():__mul(2)

Shouldn't this:

   newpt = bot:getLoc() * 2
Without knowing anything else about your situation, it looks like you
set __mul on the table itself, rather than on its metatable.


I'm not sure that's correct:

  for k,v in pairs(getmetatable(bot:getLoc())) do

Results in:

lenSquared      function: 01875200
__mul   function: 01877168
distanceTo      function: 01875330
__add   function: 01877198
distSquared     function: 01875298
len     function: 01875258
getxy   function: 018751C0
angleTo function: 018752D8
new     function: 018771C8

I know I probably haven't provided enough information, but I'm not really sure what would be helpful without just dumping an overwhelming amount of data into this message.

bot:getLoc returns a C++ class called a Point, which is translated to a Lua class by the same name by Lunar. I can add methods to the Point metatable by altering a table called Point (created by Lunar). So I added a method called __mul(), which works when called as shown in my original post, but not when used with the * operator.