BizHawk 2.9 now with Lua 5.4

Starting with BizHawk 2.9 which released on 2023-04-07 the Lua engine updated from Lua 5.1 to Lua 5.4. This page is meant to document some important or useful changes with examples.
To check which version you are currently running, you can execute:
print(_VERSION)
-- Lua 5.4

64-bit integers

Previously, all numbers in Lua were double-precision floating-point numbers. But now integers can use the full 64-bit range for calculations.
They also wrap around properly, so recreating big number arithmetic of games will not run into precision errors. This only works as long as you are careful to not go into decimal numbers.
rng = 0
function advanceRNG()
  rng = rng * 0x41C64E6D + 0x3039
end

for i = 1,30 do
  advanceRNG()  -- advance rng 30 times
end

--print(rng % (2^31))
-- Before: 0 (loss of precision)

print(rng & 0x7FFFFFFF)
-- After: 371038354 (correct!)

Floor division (//)

A very useful new operator is the floor division e.g. a // b which had to be done manually with math.floor(a / b) previously.
-- Before:
math.floor(7/2) -- 3

-- After:
7//2  -- 3

Bitwise operators

Lua has now true bitwise operators without using the bit library.

Further reading


HomePages/Masterjun/Bizhawk29Lua last edited by adelikat on 9/2/2023 3:13 PM
Page History Latest diff List referrers View Source