Back to Page
Revision 2 (current)
Edited by adelikat on 9/2/2023 3:13 PM
! 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:
%%SRC_EMBED Lua
print(_VERSION)
-- Lua 5.4
%%END_EMBED
----
! 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.
%%SRC_EMBED Lua
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!)
%%END_EMBED
! 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.
%%SRC_EMBED Lua
-- Before:
math.floor(7/2) -- 3
-- After:
7//2 -- 3
%%END_EMBED
! Bitwise operators
Lua has now true bitwise operators without using the {{bit}} library.
* {{&}}: bitwise AND
* {{|}}: bitwise OR
* {{~}}: bitwise exclusive OR
* {{>>}}: right shift
* {{<<}}: left shift
* {{~}}: unary bitwise NOT
----
! Further reading
* BizHawk Lua Function Wiki Page: [Bizhawk/LuaFunctions].
* Open the in-program documentation by pressing F1 on the Lua Console, or click Help → Lua Function List.
* For official Lua documentation, here are the links with the changes from 5.1 [http://www.lua.org/manual/5.2/readme.html#changes|→ 5.2], [http://www.lua.org/manual/5.3/readme.html#changes|→ 5.3], [http://www.lua.org/manual/5.4/readme.html#changes|→ 5.4].