lua-users home
lua-l archive

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


On Sun, Feb 7, 2010 at 6:51 PM, Majic <majic.one@gmail.com> wrote:
> Another thing to think about with % vs. math.mod()... % can be
> overloaded if I'm not mistaken. :>  __mod?

Well, yes and no - you *can* use the metamethod to set a custom
behaviour for the % operator, but only for tables and full userdata -
you *can't* use it to replace the standard behaviour for numbers:

>debug.setmetatable(1, {__mod = function()  return 12345;  end})
>print(1 % 10)
1

...so, while technically it is a change from math.mod(), it would
really only be in cases where math.mod() would throw an error because
it was given invalid arguments.

-Duncan