lua-users home
lua-l archive

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

> May I ask you (and others) why you need boolean operators in Lua? (This
> is not a rhetorical question. I really want to know what uses boolean
> operators may have in Lua.)

Some time ago, a wrote some bindings to libraries that uses bitwise OR to
combine options. So, people using something like
  xxx_type *hl xxx_open("~/", XXX_CREATE | XXX_SOMETHING_ELSE);

will not be confused when porting code to Lua:
   local hl ="~/", xxx.CREATE + xxx.SOMETHING_ELSE)

Also, I already needed to write a parser for a binary file format with
bitvector fields. At time, I used bitlib, but, with bitwise operators, the
code would be something like:

    local somebyte = fp:read(1):byte()
    local somedata = {
        somefield = (somebyte & 1) ~= 0,
        otherfield = (somebyte & 2) ~= 0,
        evenotherfield = (somebyte & 4) ~= 0

Alexandre Erwin Ittner -
OpenPGP pubkey 0x0041A1FB @