lua-users home
lua-l archive

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

Dňa 2011-11-03 0:07, HyperHacker  wrote / napísal(a):

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
complex operations.

This really seems like one of the rare cases where adding a feature
would be a significant improvement while only slightly increasing the
code size.

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.

sorry for late answer, I didn't note question.
~= is corectly maintained.

lualubit is reworked now for Lua release 5.2.0
and more info is on (with some potential problems for discuss)

One more argument for bitwise operators:
in MySQL I have table (12044 records) with column
by SQL command 
  SELECT modop,modop+0 FROM table_name;
I can have textual and numerical representation of flags:
M_ALARM_MIN,M_ARCH_ZME,M_REVRZ_AL                                        161       ... = (1<<0)|(1<<5)|(1<<7)
    With bitwise operators I can deal with data from this column as with unsigned numbers ... 4 bytes each
    without: I need for each record table with 8 items ...

Maybe interesting can be colored view of lualubit changes in Lua 5.2.0 sources :

Simple test of operator corectness is here: