lua-users home
lua-l archive

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

>Anyone considered adding a += (and -=, /=. *=) operator to lua?

Yes, I think this has been discussed before.

>I notice I have a lot of code that does stuff like:
>self.x = self.x + dx
>I'm guessing that:
>self.x += dx 
>could be compiled to something with fewer table look-ups and instructions(?)

I doubt it, because of the possibility of tag methods coming into action.

Right now, the bytecode for "self.x = self.x + dx" is

  GETGLOBAL       0       ; self
  PUSHSTRING      1       ; "x"
  GETGLOBAL       0       ; self
  GETDOTTED       1       ; x
  GETGLOBAL       2       ; dx
  SETTABLE        3 3

Except for the two GETGLOBAL for self, I don't see how this can be shortened.