Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

How about lua does not have an operator to do xor or two integers? Seriously! Once I tried to write a wireshark plugin and used lua and found out I had to implement my own xor function! Stupidest thing I have done...


See http://bitop.luajit.org/

It comes standard as part of LuaJIT, which is likely what should be used for anything like a wireshark plugin (I don't know what wireshark actually uses, but LuaJIT is a drop-in replacement for the most part).

Bitop (or something similar) is included in Lua 5.2 as well.


On the one hand, by (interpreter compile-time) default, all numeric values in Lua are floats, and xor on floats doesn't make a lot of sense. On the other hand, given the popularity of embedded Lua (in which case the numeric type is probably int) the lack of bitwise operators gets frustrating. Actually I can attest to this, having used Lua in an embedded context.


Actually, by default numeric values are doubles, which can easily handle a 32-bit int without losing precision. And as I posted above, the Lua bitop library (which is standard in LuaJIT and Lua 5.2) gives you bitwise operations.


I did use bitop extensively. Having every bitwise operation be a function call was not as pleasant to type (or read) as dedicated bitwise operators but it did get the job done.


There are a few lines in pure Lua by the author of the language:

http://lua-users.org/lists/lua-l/2002-09/msg00134.html

If you can load a C extension module then there's:

http://bitop.luajit.org/

Yes Lua is that small.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: