I’ve wondered a lot of this question too, so I don’t have all the answers but I’ll share what I’ve figured out so far:
Is the internal integer type is lua a 32bit integer or 64bit integer
All numbers in Lua 5.1 are 64-bit, but they’re double floating points, so they can store 2^53 negative and positive integers (9,007,199,254,740,992) with full-precision. You can store higher numbers (up to 2^1023 more or less), at a loss of precision.
local max = 36028797018963968 -- 2^55
local sub = max - 5
print(max) --3.6028797018964e+16
print(max - sub) -- 4 (number was rounded)
For this reason, bit prefers to operate on 32-bit integers (and that they’re available for all platforms).
advice about how to use 64 bit bitwise operation in lua in Defold
I think it depends on what you’re trying to do. If you’re storing data or tracking states, the easiest answer is to split it up into multiple 32-bit integers if you can.
If you absolutely need 64-bit bitops, you’ll have to use the FFI: FFI Semantics. This does mean your project can’t be used in HTML5.
I haven’t done this in a while, so please forgive the representation here, but you could always use additional registers at the cost of one bit. (I’m sure someone has already made a lua module that does this)
1 | 2 -- registers
0111 | 0000 -- 7 in register 1. Add 2 to register 1
1001 | 0000 -- Overflow to (-)9. Add 1 to register 2
1001 | 0001 -- (-)9 in register 1, 1 in register 2. Register 1 = bit.band(register1, register2)
0001 | 0001 -- 9