Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Lua/Runtime/LuaVirtualMachine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2306,7 +2306,7 @@ static bool ExecuteCompareOperationMetaMethod(LuaValue vb, LuaValue vc,
return true;
}

if (opCode == OpCode.Le)
if (opCode == OpCode.Le && !reverseLe)
{
reverseLe = true;
name = Metamethods.Lt;
Expand Down Expand Up @@ -2392,7 +2392,7 @@ internal static async ValueTask<bool> ExecuteCompareOperationMetaMethod(LuaState
}
}

if (opCode == OpCode.Le)
if (opCode == OpCode.Le && !reverseLe)
{
reverseLe = true;
name = Metamethods.Lt;
Expand Down
35 changes: 34 additions & 1 deletion tests/Lua.Tests/OperatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,39 @@ namespace Lua.Tests;

public class OperatorTests
{
[Test]
public void NilGreaterThan_ThrowsRuntimeException()
{
var state = LuaState.Create();

var ex = Assert.ThrowsAsync<LuaRuntimeException>(async () =>
await state.DoStringAsync("local test = nil > 5").AsTask());

Assert.That(ex!.Message, Does.Contain("attempt to compare a number value with a nil value"));
}

[Test]
public void NilGreaterThanOrEquals_ThrowsRuntimeException()
{
var state = LuaState.Create();

var ex = Assert.ThrowsAsync<LuaRuntimeException>(async () =>
await state.DoStringAsync("local test = nil >= 5").AsTask());

Assert.That(ex!.Message, Does.Contain("attempt to compare a number value with a nil value"));
}

[Test]
public void GreaterThanOrEqualsNil_ThrowsRuntimeException()
{
var state = LuaState.Create();

var ex = Assert.ThrowsAsync<LuaRuntimeException>(async () =>
await state.DoStringAsync("local test = 5 >= nil").AsTask());

Assert.That(ex!.Message, Does.Contain("attempt to compare a nil value with a number value"));
}

[TestCase(1, 6)]
[TestCase(2, 7)]
[TestCase(3, 8)]
Expand Down Expand Up @@ -137,4 +170,4 @@ public async Task Test_GreaterThanOrEquals(double a, double b)
Assert.That(result, Has.Length.EqualTo(1));
Assert.That(result[0], Is.EqualTo(new LuaValue(a >= b)));
}
}
}
Loading