3 ms·
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 imple
by cybernytrix 15y ago
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...
- SomeCallMeTim 15y agoSee http://bitop.luajit.org/ 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.
- acqq 15y agoThere are a few lines in pure Lua by the author of the language: http://lua-users.org/lists/lua-l/2002-09/msg00134.html 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/ http://bitop.luajit.org/ Yes Lua is that small.
- tesseract 15y agoOn 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.
- SomeCallMeTim 15y agoActually, 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.
- tesseract 15y agoI 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.