lua-users home
lua-l archive

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



On 27-Aug-05, at 10:23 AM, Aaron Brown wrote:

Rici wrote:

I'd put bit operations in string.*, not math.*.  We can
argue about this after 5.1 comes out.

Forgive me for jumping the gun, but I'd be interested in
seeing what kind of interface you're thinking of.  Do you
imagine them taking or returning strings?  What kinds?
(Maybe something like string.char(1, 1) represents
0000 0001 0000 0001 i.e., 257?)

Both taking and returning strings.

Numbers have a fixed but unspecified length, so you cannot reliably test bit `i' in a number; you have no way of knowing whether `i' is in range or not.

I use bit operations for fairly long bit strings. Using bits in a number in order to compress a small number of "flags" into a single operation strikes me as an abuse both of flags and numbers, but that might be just me being a purist.

Strings are immutable, so you cannot "set" a bit; you need to create a new bit string with a "bitor" operation. In practice, that is often convenient because the resulting bit strings are interned and can be used as table keys (in some applications, that's exactly what you want; in others, it's a little bit of regrettable overhead).