Skip to content

Commit 74a404a

Browse files
authored
5.0: Emulate % with native math.mod() (#1370)
* refactor(5.0): emulate modulo with native math.mod() * refactor(5.0): remove the modulo lualib feature altogether
1 parent 9244f54 commit 74a404a

File tree

3 files changed

+2
-7
lines changed

3 files changed

+2
-7
lines changed

src/LuaLib.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ export enum LuaLibFeature {
5252
MathAtan2 = "MathAtan2",
5353
MathModf = "MathModf",
5454
MathSign = "MathSign",
55-
Modulo50 = "Modulo50",
5655
New = "New",
5756
Number = "Number",
5857
NumberIsFinite = "NumberIsFinite",

src/lualib/Modulo50.ts

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/transformation/visitors/binary-expression/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ function transformBinaryOperationWithNoPrecedingStatements(
7070
}
7171

7272
if (operator === ts.SyntaxKind.PercentToken && context.luaTarget === LuaTarget.Lua50) {
73-
return transformLuaLibFunction(context, LuaLibFeature.Modulo50, node, left, right);
73+
const mathMod = lua.createTableIndexExpression(lua.createIdentifier("math"), lua.createStringLiteral("mod"));
74+
return lua.createCallExpression(mathMod, [left, right], node);
7475
}
7576

7677
let luaOperator = simpleOperatorsToLua[operator];

0 commit comments

Comments
 (0)