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 http://sourceforge.net/projects/lualubit/files/
and more info is on http://www.sbmintegral.sk/lua (with some potential problems for discuss)

One more argument for bitwise operators:
in MySQL I have table (12044 records) with column
  `modop` set('M_ALARM_MIN','M_ALARM_MAX','M_ARCH_SEK','M_ARCH_MIN','M_ARCH_HOD','M_ARCH_ZME','M_DBL_AMAX','M_REVRZ_AL')
by SQL command 
  SELECT modop,modop+0 FROM table_name;
I can have textual and numerical representation of flags:
example
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 : http://www.sbmintegral.sk/lua/diff_all_files.html

Simple test of operator corectness is here:  http://www.sbmintegral.sk/lua/console_explain.html