lua-users home
lua-l archive

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



On 20-Sep-06, at 3:51 PM, Roberto Ierusalimschy wrote:

Actually, I think he was just talking about needing to use 'and', 'or' and
'not' instead of '&&', '||', and '!' --- Lua *has* boolean operators.

But I think you were talking about logical operators, which stock Lua doesn't
have, [...]

Sure. Sorry about the confusion. (I should call them bitwise operators.)

-- Roberto

I find bitwise operators useful for representing large subsets; however, a bitset limited to some k < 64 is not very useful for that, so i generally use a library which keeps the bitsets as strings (although it turns out that the standard hash algorithm on strings is not very good for typical bitstrings, but it is
not horrible either, and I haven't come up with a better one.) It's not
always necessary to intern bitsets, but it is often useful.

If the subsets are not large, then it's better to represent them as
interval lists, which can also be condensed into strings.

I doubt whether these applications are general enough to be worth including
in core Lua, though.

For the case of flags coming out of C functions, I personally think that
it is better to translate the flagset in and out into a more usable Lua
structure than to try to use bitwise operators in Lua. That's just a personal
preference, but it leads to more readable Lua programs, even though they
may not execute quite as fast.