lua-users home
lua-l archive

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


Eike Decker wrote:

Actually you don't need bitwise OR to do that kind of operation. You
could also write:

ExplodePlayerIfWASDIsPressed(FLAG_KEYBOARD_W + FLAG_KEYBOARD_A +
  FLAG_KEYBOARD_S + FLAG_KEYBOARD_D)

The + operation is equivalent (to my knowledge) to the bitwise |
operation as long as the bits that are used are not overlapping, for
example (binary):
010 + 100 = 010 | 100 = 110
010 + 010 = 100  ~= 010 | 010 = 010

Combining bit flags with an add operation works well that way as long
as this is respected. Even if true bitwise OR is needed, you could
still write a wrapper to handle it this way:

ExplodePlayerIfWASDIsPressed( bOR(FLAG_KEYBOARD_W, FLAG_KEYBOARD_A,
FLAG_KEYBOARD_S, FLAG_KEYBOARD_D))

... which would hardly be more ugly than the C-like counterpart.

Eike
True, I guess we'll leave it up to Roberto to decide unless someone can present a convincing counter-argument. (If he ever decides to tell us what he doesn't like about our current implementations.)