Skip to content

Commit a4330cb

Browse files
committed
Fix: Default loop expression step (#138)
1 parent ae0bbc4 commit a4330cb

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

NeoLua/Parser.cs

+9-1
Original file line numberDiff line numberDiff line change
@@ -1969,8 +1969,16 @@ private static void ParseForLoop(Scope scope, ILuaLexer code)
19691969
code.Next();
19701970
loopStep = ParseExpression(scope, code, InvokeResult.Object, scope.EmitExpressionDebug);
19711971
}
1972+
else if (loopStart.Type == typeof(int))
1973+
loopStep = Expression.Constant(1);
1974+
else if (loopStart.Type == typeof(long))
1975+
loopStep = Expression.Constant(1L);
1976+
else if (loopStart.Type == typeof(float))
1977+
loopStep = Expression.Constant(1.0f);
1978+
else if (loopStart.Type == typeof(double))
1979+
loopStep = Expression.Constant(1.0);
19721980
else
1973-
loopStep = Expression.Constant(1, loopStart.Type);
1981+
loopStep = Expression.Constant(Lua.RtConvertValue(1, loopStart.Type));
19741982

19751983
var loopScope = new LoopScope(scope);
19761984
var loopVarParameter = loopScope.RegisterVariable(typeLoopVar == typeof(object) ? LuaEmit.LiftType(LuaEmit.LiftType(loopStart.Type, loopEnd.Type), loopStep.Type) : typeLoopVar, tLoopVar.Value);

0 commit comments

Comments
 (0)