[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: native code for bitwise operators in LUA
- From: HyperHacker <hyperhacker@...>
- Date: Wed, 2 Nov 2011 17:07:01 -0600
On Wed, Nov 2, 2011 at 15:43, Patrick Rapin <email@example.com> wrote:
> I do use quite a lot bitwise operators in C++.
> In Lua 5.1, bit operations missed me a lot so I wrote a bit library
> (instead of searching for an existent one).
> So I am happy that a standard bit32 library now appears in Lua 5.2.
> However, I am clearly against introducing new operators and new VM op
> codes for bit operations:
> - Lua has very few punctuation operators, privileging key words.
> - Lua lacked bitwise operations during 18 years; I doubt that they
> became suddenly so important to change the grammar for them
> - Lua always favors small implementation code when possible. New
> opcodes and operators are harder to introduce, and cannot be
> - Even MATLAB doesn't have operators for bit operations
> - If you want speed, use LuaJIT
I've often wished Lua had infix bitwise operators. There are patches
for it (such as this one), but such significant patches make it not
really Lua anymore. You can also hack some metatable tricks to make
things like (1) '<<' (3) work, but that's still ugly (and I dread to
think of its efficiency). The bit library only provides prefix
operators which I find quite a bit harder to read when dealing with
This really seems like one of the rare cases where adding a feature
would be a significant improvement while only slightly increasing the
As for this particular patch, I see ~ and !... that doesn't change the
meaning of ~=, does it? Even if not, it makes it a bit confusing, with
~ now having different meanings in different contexts.
Sent from my toaster.