[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Next Version of Lua?
- From: Eike Decker <zet23t@...>
- Date: Wed, 10 Jun 2009 11:58:45 +0200
> local WASDActive = bitmap.Create(FLAG_KEYBOARD_W, FLAG_KEYBOARD_A,
> FLAG_KEYBOARD_S, FLAG_KEYBOARD_D)
> ExplodePlayerIfWASDIsPressed(WASDActive:GetValue())
>
> Instead of:
>
> ExplodePlayerIfWASDIsPressed(FLAG_KEYBOARD_W | FLAG_KEYBOARD_A |
> FLAG_KEYBOARD_S | FLAG_KEYBOARD_D)
>
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