From d5c7e534195f07226eeee1714434041e41764a8a Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Mon, 9 Feb 2026 04:46:40 +0000 Subject: [PATCH 1/8] [lua] Fix Math.atan2 on lua 5.5 In lua 5.3, math.atan2 was deprecated in favour of a two argument version of math.atan. In 5.5, math.atan2 has finally been removed so if atan2 is missing at runtime we should use atan instead. If 5.3 is targetted explicitly, we can assume that atan will take two arguments so we don't have to do a runtime check. --- std/lua/Math.hx | 12 ++++++++++-- std/lua/_std/Math.hx | 13 +++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/std/lua/Math.hx b/std/lua/Math.hx index f659c2789c3..188c30d595d 100644 --- a/std/lua/Math.hx +++ b/std/lua/Math.hx @@ -65,15 +65,23 @@ extern class Math { static function asin(x:Float):Float; /** - Returns the arc tangent of x (in radians). + Returns the arc tangent of y/x (in radians), using the signs of both arguments to find the quadrant of the result. It also handles correctly the case of x being zero. + + The default value for x is 1, so that the call math.atan(y) returns the arc tangent of y. + + The x argument is ignored on lua 5.2 or older, where atan2 was used instead. **/ - static function atan(x:Float):Float; + static function atan(y:Float, ?x:Float):Float; + #if !(lua_ver >= 5.5) /** Returns the arc tangent of y/x (in radians), but uses the signs of both parameters to find the quadrant of the result. (It also handles correctly the case of x being zero.) + + Deprecated in lua 5.3 and removed in 5.5. **/ static function atan2(y:Float, x:Float):Float; + #end /** Returns the cosine of x (assumed to be in radians). diff --git a/std/lua/_std/Math.hx b/std/lua/_std/Math.hx index 9b168d92efe..5e47ab3e456 100644 --- a/std/lua/_std/Math.hx +++ b/std/lua/_std/Math.hx @@ -93,8 +93,17 @@ class Math { public static inline function random():Float return untyped __define_feature__("Math.random", lua.Math.random()); - public static inline function atan2(y:Float, x:Float):Float - return lua.Math.atan2(y, x); + #if (lua_ver >= 5.3) + public static inline function atan2(y:Float, x:Float):Float { + return lua.Math.atan(y, x); + } + #else + private static final atan2Impl = lua.Math.atan2 ?? lua.Math.atan; + + public static inline function atan2(y:Float, x:Float):Float { + return atan2Impl(y, x); + } + #end public static function max(a:Float, b:Float):Float { return Math.isNaN(a) || Math.isNaN(b) ? Math.NaN : lua.Math.max(a, b); From a11a76d60e0db03766151ecfaf167ca25dc56318 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Mon, 9 Feb 2026 04:51:16 +0000 Subject: [PATCH 2/8] [tests] Add lua 5.5 to testing --- tests/runci/targets/Lua.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/runci/targets/Lua.hx b/tests/runci/targets/Lua.hx index 7fe36625768..3591354c1fb 100644 --- a/tests/runci/targets/Lua.hx +++ b/tests/runci/targets/Lua.hx @@ -90,7 +90,7 @@ class Lua { getLuaDependencies(); - for (lv in ["-l5.1", "-l5.2", "-l5.3", "-l5.4", "-j2.0", "-j@v2.1"]) { + for (lv in ["-l5.1", "-l5.2", "-l5.3", "-l5.4", "-l5.5", "-j2.0", "-j@v2.1"]) { // luajit 2.0 was missing arm64 support if (System.arch == Arm64 && lv == "-j2.0") continue; From e81589b932a06aa717b3e73e7604b4e5c976c25b Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Fri, 27 Feb 2026 01:08:02 +0000 Subject: [PATCH 3/8] [tests] Update lua-utf8 for lua 5.5 Lua 5.5 requires 0.1.7+, but 0.1.7 to 0.2.0 have a bug with invalid arguments to utf8.char. 0.2.1 gives 5.5 support and fixes the argument issue. --- tests/runci/targets/Lua.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/runci/targets/Lua.hx b/tests/runci/targets/Lua.hx index 3591354c1fb..8cc21f15b63 100644 --- a/tests/runci/targets/Lua.hx +++ b/tests/runci/targets/Lua.hx @@ -143,7 +143,7 @@ class Lua { installLib("https://raw.githubusercontent.com/lunarmodules/lua-compat-5.3/refs/heads/master/rockspecs/bit32-scm-1.rockspec", ""); installLib("https://raw.githubusercontent.com/luvit/luv/refs/heads/master/luv-scm-0.rockspec", ""); - installLib("luautf8", "0.1.6-1"); + installLib("luautf8", "0.2.1-1"); installLib("https://raw.githubusercontent.com/HaxeFoundation/hx-lua-simdjson/master/hx-lua-simdjson-scm-1.rockspec", ""); From 39b1827ac323d6b2a9dd18c1e2d4dc434b798a4e Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Thu, 9 Apr 2026 18:14:14 +0100 Subject: [PATCH 4/8] [lua] Hide math functions removed in lua 5.5 --- std/lua/Math.hx | 42 ++++++++++++++++++++++++++++++++---------- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/std/lua/Math.hx b/std/lua/Math.hx index 188c30d595d..744d0b78e5e 100644 --- a/std/lua/Math.hx +++ b/std/lua/Math.hx @@ -77,9 +77,10 @@ extern class Math { /** Returns the arc tangent of y/x (in radians), but uses the signs of both parameters to find the quadrant of the result. (It also handles correctly the case of x being zero.) - - Deprecated in lua 5.3 and removed in 5.5. **/ + #if (lua_ver >= 5.3) + @:deprecated("Deprecated in Lua 5.3, removed in Lua 5.5") + #end static function atan2(y:Float, x:Float):Float; #end @@ -89,29 +90,40 @@ extern class Math { static function cos(x:Float):Float; /** - Returns the hyperbolic cosine of x. + Returns the sine of x (assumed to be in radians). **/ - static function cosh(x:Float):Float; + static function sin(x:Float):Float; /** - Returns the sine of x (assumed to be in radians). + Returns the tangent of x (assumed to be in radians) **/ - static function sin(x:Float):Float; + static function tan(x:Float):Float; + #if !(lua_ver >= 5.5) /** - Returns the hyperbolic sine of x. + Returns the hyperbolic cosine of x. **/ - static function sinh(x:Float):Float; + #if (lua_ver >= 5.3) + @:deprecated("Deprecated in Lua 5.3, removed in Lua 5.5") + #end + static function cosh(x:Float):Float; /** - Returns the tangent of x (assumed to be in radians) + Returns the hyperbolic sine of x. **/ - static function tan(x:Float):Float; + #if (lua_ver >= 5.3) + @:deprecated("Deprecated in Lua 5.3, removed in Lua 5.5") + #end + static function sinh(x:Float):Float; /** Returns the hyperbolic tangent of x. **/ + #if (lua_ver >= 5.3) + @:deprecated("Deprecated in Lua 5.3, removed in Lua 5.5") + #end static function tanh(x:Float):Float; + #end /** Returns the angle x (given in degrees) in radians. @@ -128,10 +140,15 @@ extern class Math { **/ static function fmod(x:Float):Float; + #if !(lua_ver >= 5.5) /** Returns y-th power of x. **/ + #if (lua_ver >= 5.3) + @:deprecated("Deprecated in Lua 5.3, removed in Lua 5.5") + #end static function pow(x:Float, y:Float):Float; + #end /** Returns the square root of x. @@ -158,10 +175,15 @@ extern class Math { **/ static function log(x:Float):Float; + #if !(lua_ver >= 5.5) /** Returns the base-10 logarithm of x. **/ + #if (lua_ver >= 5.2) + @:deprecated("Deprecated in Lua 5.2, removed in Lua 5.5") + #end static function log10(x:Float):Float; + #end /** Returns the maximum value among its arguments. From 24f19aadf94712d6cc81a842479d4cc5ea807926 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Thu, 9 Apr 2026 18:16:09 +0100 Subject: [PATCH 5/8] [lua] Add remaining 5.3 deprecations These were deprecated in 5.3 but still exist even in lua 5.5. --- std/lua/Math.hx | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/std/lua/Math.hx b/std/lua/Math.hx index 744d0b78e5e..6f3851ac5e6 100644 --- a/std/lua/Math.hx +++ b/std/lua/Math.hx @@ -163,11 +163,17 @@ extern class Math { /** Returns m and e such that x = m2^e, e is an integer and the absolute value of m is in the range [0.5, 1) (or zero when x is zero). **/ + #if (lua_ver >= 5.3) + @:deprecated("Deprecated in Lua 5.3") + #end static function frexp(x:Float):MathFrexpResult; /** Returns m2^e (e should be an integer). **/ + #if (lua_ver >= 5.3) + @:deprecated("Deprecated in Lua 5.3") + #end static function ldexp(m:Float, e:Int):Float; /** From 8164054f4e9e03b748efe9bd3d50049799a83aa9 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Thu, 9 Apr 2026 18:37:59 +0100 Subject: [PATCH 6/8] [lua] Avoid Math.pow deprecation warning The exponent operator is available in all supported lua versions so we can use that instead. math.pow is deprecated in lua 5.3 and removed in lua 5.5. --- std/lua/_std/Math.hx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/std/lua/_std/Math.hx b/std/lua/_std/Math.hx index 5e47ab3e456..fa36315467c 100644 --- a/std/lua/_std/Math.hx +++ b/std/lua/_std/Math.hx @@ -114,7 +114,7 @@ class Math { } public static inline function pow(v:Float, exp:Float):Float - return lua.Math.pow(v, exp); + return lua.Syntax.code("(({0}) ^ ({1}))", v, exp); public static inline function round(v:Float):Int return Math.floor(v + 0.5); From 35e35d67f0c8cfb3133aaec9ad3c340b80d6897e Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Thu, 9 Apr 2026 18:59:53 +0100 Subject: [PATCH 7/8] [lua] Simplify luajit and lua 5.1/5.2 Math.atan2 When targetting these versions we know that atan2 is available so we can use it directly. --- std/lua/_std/Math.hx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/std/lua/_std/Math.hx b/std/lua/_std/Math.hx index fa36315467c..e8cb73bdafd 100644 --- a/std/lua/_std/Math.hx +++ b/std/lua/_std/Math.hx @@ -94,9 +94,11 @@ class Math { return untyped __define_feature__("Math.random", lua.Math.random()); #if (lua_ver >= 5.3) - public static inline function atan2(y:Float, x:Float):Float { + public static inline function atan2(y:Float, x:Float):Float return lua.Math.atan(y, x); - } + #elseif (lua_ver <= 5.2 || luajit) + public static inline function atan2(y:Float, x:Float):Float + return lua.Math.atan2(y, x); #else private static final atan2Impl = lua.Math.atan2 ?? lua.Math.atan; From edf44867a375d12fcf1b2d603261c7e720eca647 Mon Sep 17 00:00:00 2001 From: Tobiasz Laskowski Date: Thu, 9 Apr 2026 19:01:44 +0100 Subject: [PATCH 8/8] [lua] Remove 2nd atan argument for lua 5.1/5.2/jit --- std/lua/Math.hx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/std/lua/Math.hx b/std/lua/Math.hx index 6f3851ac5e6..3bcfda97cb4 100644 --- a/std/lua/Math.hx +++ b/std/lua/Math.hx @@ -64,14 +64,23 @@ extern class Math { **/ static function asin(x:Float):Float; + #if (lua_ver <= 5.2 || luajit) /** Returns the arc tangent of y/x (in radians), using the signs of both arguments to find the quadrant of the result. It also handles correctly the case of x being zero. The default value for x is 1, so that the call math.atan(y) returns the arc tangent of y. + **/ + static function atan(y:Float):Float; + #else + /** + Returns the arc tangent of y/x (in radians), using the signs of both arguments to find the quadrant of the result. It also handles correctly the case of x being zero. - The x argument is ignored on lua 5.2 or older, where atan2 was used instead. + The default value for x is 1, so that the call math.atan(y) returns the arc tangent of y. + + The x argument is ignored on lua 5.2 or older and luajit, where atan2 is available instead. **/ static function atan(y:Float, ?x:Float):Float; + #end #if !(lua_ver >= 5.5) /**