Skip to content

fix Math.atan2 emitting math.atan2 instead of math.atan for Lua 5.4+#1700

Merged
Perryvw merged 2 commits intoTypeScriptToLua:masterfrom
RealColdFry:fix/math-atan2-lua53-plus
Apr 1, 2026
Merged

fix Math.atan2 emitting math.atan2 instead of math.atan for Lua 5.4+#1700
Perryvw merged 2 commits intoTypeScriptToLua:masterfrom
RealColdFry:fix/math-atan2-lua53-plus

Conversation

@RealColdFry
Copy link
Copy Markdown
Contributor

Math.atan2(y, x) emits math.atan2(y, x) for Lua 5.4 and 5.5 targets, but math.atan2 was deprecated in 5.3 (replaced by two-arg math.atan(y, x)). 5.3 still has both, and 5.4 keeps math.atan2 behind -DLUA_COMPAT_5_3 (hardcoded in the stock Makefile). 5.5 drops the compat flag, so math.atan2 is just nil and you get a runtime error.

The codegen only special-cased === Lua53 when choosing math.atan vs math.atan2. That was correct when written (2019, before 5.4/5.5 targets existed) but never got updated when those targets were added.

Tests didn't catch this because getLuaBindingsForVersion in test/util.ts falls through to the 5.4 WASM for 5.5, and the 5.4 WASM is built with compat enabled, so math.atan2 exists and the test passes.

math.atan2 was removed in Lua 5.3 (replaced by two-arg math.atan).
The codegen only special-cased 5.3 but not 5.4 or 5.5, which also
lack math.atan2 (5.4 has it behind a compat flag, 5.5 drops it).
Enumerate the older targets that need math.atan2 instead of the newer
ones that need math.atan, so any future Lua target (5.6+) defaults to
the modern behavior rather than silently regressing.
@RealColdFry RealColdFry marked this pull request as ready for review March 30, 2026 13:33
@Perryvw Perryvw merged commit 84ef0b2 into TypeScriptToLua:master Apr 1, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants