Implement += etc for custom class?

Hi! I have a 'class' that represents very large numbers, which I'd like to implement Playdate's custom operator += for. I've no idea how to do that! Can anyone help? It's not a biggie, I will just write :add in the meantime.

Unfortunately, custom operators aren't a feature of Lua. Our arithmetic assignment operators such as += had to be implemented directly in the pdc compiler, because there isn't a language-level way of doing it. Sorry about that.

No problem! Thanks for the fast response. Figured it was a long shot :smiley:

Under the hood the compiler turns a += b into a = a + b, so it'll use an _add metamethod as expected in that case. See Programming in Lua : 13.1 for an example.

1 Like

Ohhh awesome thank you!