Expand description
bit32 — the Lua 5.2/5.3 32-bit bitwise library.
C source: reference/lua-5.4.7/src/lbitlib.c.
bit32 was introduced in Lua 5.2 and removed in 5.4 once native 64-bit
bitwise operators (& | ~ << >>) arrived in 5.3. In a stock build it
is present in both 5.2 and 5.3 — 5.3 keeps it under the default-on
LUA_COMPAT_BITLIB flag — so init registers it under the
V52 | V53 gate. Verified against the reference binaries: type(bit32) is
nil / table / table / nil for 5.1 / 5.2 / 5.3 / 5.4. That gate is
load-bearing; narrowing it to 5.2-only would drop a 5.3 builtin.
Every operation masks its operands and result to 32 bits (mod 2^32):
this unsigned 32-bit window is the library’s defining semantics and is what
distinguishes it from 5.3’s native 64-bit operators.
§Graduation (idiomatization sprint 2)
The whole 5.2/5.3 surface is implemented and reference-pinned:
band bor bxor bnot btest lshift rshift arshift lrotate
rrotate extract replace. The behavioral net lives in
crates/lua-stdlib/tests/bit32_strengthen.rs (pinned to lua5.2.4, with a
lua5.3.6 contrast for the one version-specific behavior — see [arg_u32]).
Functions§
- open_
bit32 - Open the
bit32library, leaving the populated table on the stack.