We have added bit32
library from Lua 5.2 to Roblox Lua.
You can read the documentation in Lua 5.2 manual:
https://www.lua.org/manual/5.2/manual.html#6.7
The library effectively allows you to implement various algorithms that require bit manipulation in an easier way and with better performance compared to trying to emulate the bit operations yourself.
While Lua doesn’t support integers natively, the bit32
library converts input arguments to 32-bit integers and proceeds to do bit operations in 32-bits. Note that the numbers are unsigned - for example bit32.bnot(0)
is equal to 0xffffffff
, not -1
.
In the future we hope to provide optimized implementations of various popular transforms for cryptography, hashing and compression, but we felt that a general bit manipulation utility is also useful.
Note, right now the new Lua VM does not optimize these operations in a special way, but we plan to update it with first-class support for some functions from bit32
, math
, string
libraries in the future to accelerate these.
Please let us know if you find any issues, and feel free to publish implementations of various algorithms in the Community Resources category for others to use.