lua-users home
lua-l archive

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


Mike Pall wrote:
this is a patch relative to Lua 5.1 alpha:

- The lexer now parses hex numbers (e.g. 0x1234 == 4660).

- luaO_str2d has a fallback for non C99 compliant systems
  (used by tonumber() and by the lexer).

- String literals allow hex escape sequences (e.g. "\x40" == "@").

- New bit operations:

  y = math.bitor(x1, x2)
  y = math.bitand(x1 [, x2])   x2 = -1 if omitted (i.e. tobit)
  y = math.bitxor(x1 [, x2])   x2 = -1 if omitted (i.e. bitnot)

Why not a variable number of arguments?
y = math.bitor(0x12, 0x34, 0x56)
looks nicer than
y = math.bitor(0x12, math.bitor(0x34, 0x56))
Isn't it?

Mmm, these names sound funny in French...

  y... = math.bitfield(x, start [, len] ...)
    'start' is the bit position relative to the lsb (bit 0)
    It's a right/left shift for a positive/negative 'start'.
    It's a pure shift if 'len' is omitted.
    Otherwise the result is masked to 'len' valid bits.

Not very user friendly, it is quite hard to figure what the examples do...
Why not make specific functions for shifting bits?

  Examples:

  bitfield(0x345678, 8)               --> 0x3456
  bitfield(0x345678, -8)              --> 0x34567800
  bitfield(0x345678, 8, 8)            --> 0x56
  bitfield(0x345678, -8, 8)           --> 0x7800
  bitfield(0x345678, 3, 10)           --> 0x2cf
  bitfield(0x345678, 0,8, 8,8, 16,8)  --> 0x78 0x56 0x34

--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --  --  --