[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: boolean operators
- From: "Alexandre Erwin Ittner" <aittner@...>
- Date: Wed, 20 Sep 2006 17:59:21 -0300 (BRT)
> 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("~/blerg.boo", XXX_CREATE | XXX_SOMETHING_ELSE);
will not be confused when porting code to Lua:
local hl = xxx.open("~/blerg.boo", 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 - aittner@netuno.com.br
OpenPGP pubkey 0x0041A1FB @ http://pgp.mit.edu