lua-users home
lua-l archive

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


>> but about the only thing I ever find myself "wanting" is bitwise
>> operations and hex literals.

DR> Yep, same here.

DR> I think a lot of the problem comes from the single Lua numeric type, which is
DR> usually a double. Lua is simple, and keeping it simple is one of the chores
DR> of the community. So we may be stuck with patches for our special purpose
DR> needs, no matter how general we may think they are.

DR> Let me know if you ever add bitwise operators to the core, and I'll do the
DR> same.

Because of the number = double problem, I never added it to the core,
but I did code a simple bit routine library:

bit.nand(n1,n2)
bit.nor(n1,n2)
bit.xor(n1,n2)
bit.lshift(n,s)
bit.rshift(n,s)
bit.invert(n)
bit.clear(n,b)
bit.reset(n,b)
bit.toggle(n,b)

Anyone who wants the code is welcome to it, but I'm sure everyone here
could just as easily whip up there own in 10 minutes.

Likewise, one other library that I've used quite often is a sample
[memory] bank library:

bank.new(size)
bank:free()
bank:resize(new_size)
bank:poke(offset,byte)
bank:peek(offset)
bank:offset(offset)
bank:size()
bank:cbyte(n)
bank:cword(n)
bank:clong(n)
bank:cstring(text)
bank:czstring(text)
bank:save(filename)

Again, anyone who wants the code, just ask. But, if libraries were to
ever be added to Lua 5.1, I personally think hex parsing and the bit
library above would be quite good to add, especially for when Lua is
being embedded.

-- 
Best regards,
 Jeff                            mailto:jma@insightbb.com