Browse Source

improve: error message

Akeit0 7 months ago
parent
commit
e97aefc8b7
3 changed files with 10 additions and 4 deletions
  1. 2 2
      src/Lua/Exceptions.cs
  2. 6 1
      src/Lua/Runtime/LuaVirtualMachine.cs
  3. 2 1
      tests/Lua.Tests/LuaTests.cs

+ 2 - 2
src/Lua/Exceptions.cs

@@ -127,12 +127,12 @@ public class LuaRuntimeException : LuaException
 
 
     public static void AttemptInvalidOperation(LuaThread? thread, string op, LuaValue a, LuaValue b)
     public static void AttemptInvalidOperation(LuaThread? thread, string op, LuaValue a, LuaValue b)
     {
     {
-        throw new LuaRuntimeException(thread, $"attempt to {op} a '{a.TypeToString()}' with a '{b.TypeToString()}'");
+        throw new LuaRuntimeException(thread, $"attempt to {op} a {a.TypeToString()} value with a {b.TypeToString()} value");
     }
     }
 
 
     public static void AttemptInvalidOperation(LuaThread? thread, string op, LuaValue a)
     public static void AttemptInvalidOperation(LuaThread? thread, string op, LuaValue a)
     {
     {
-        throw new LuaRuntimeException(thread, $"attempt to {op} a '{a.TypeToString()}' value");
+        throw new LuaRuntimeException(thread, $"attempt to {op} a {a.TypeToString()} value");
     }
     }
 
 
     internal static void AttemptInvalidOperationOnLuaStack(LuaThread thread, string op, int lastPc, int reg)
     internal static void AttemptInvalidOperationOnLuaStack(LuaThread thread, string op, int lastPc, int reg)

+ 6 - 1
src/Lua/Runtime/LuaVirtualMachine.cs

@@ -848,6 +848,7 @@ public static partial class LuaVirtualMachine
         var task = Concat(context, context.FrameBase + a, c - b + 1);
         var task = Concat(context, context.FrameBase + a, c - b + 1);
         if (task.IsCompleted)
         if (task.IsCompleted)
         {
         {
+            _ = task.Result;
             return true;
             return true;
         }
         }
 
 
@@ -1074,7 +1075,7 @@ public static partial class LuaVirtualMachine
             }
             }
             else
             else
             {
             {
-                LuaRuntimeException.AttemptInvalidOperationOnLuaStack(GetThreadWithCurrentPc(context), "call", context.Pc,instruction.A);
+                LuaRuntimeException.AttemptInvalidOperationOnLuaStack(GetThreadWithCurrentPc(context), "call", context.Pc, instruction.A);
             }
             }
         }
         }
 
 
@@ -1405,6 +1406,10 @@ public static partial class LuaVirtualMachine
     [MethodImpl(MethodImplOptions.NoInlining)]
     [MethodImpl(MethodImplOptions.NoInlining)]
     static bool GetTableValueSlowPath(LuaValue table, LuaValue key, VirtualMachineExecutionContext context, out LuaValue value, out bool doRestart)
     static bool GetTableValueSlowPath(LuaValue table, LuaValue key, VirtualMachineExecutionContext context, out LuaValue value, out bool doRestart)
     {
     {
+        // TODO: get table name if nil
+        // if (table.Type == LuaValueType.Nil)
+        // {
+        // }
         var targetTable = table;
         var targetTable = table;
         const int MAX_LOOP = 100;
         const int MAX_LOOP = 100;
         doRestart = false;
         doRestart = false;

+ 2 - 1
tests/Lua.Tests/LuaTests.cs

@@ -12,10 +12,11 @@ public class LuaTests
     [TestCase("tests-lua/constructs.lua")]
     [TestCase("tests-lua/constructs.lua")]
     [TestCase("tests-lua/locals.lua")]
     [TestCase("tests-lua/locals.lua")]
     [TestCase("tests-lua/literals.lua")]
     [TestCase("tests-lua/literals.lua")]
-    //[TestCase("tests-lua/pm.lua")] string.match is not implemented
+    //[TestCase("tests-lua/pm.lua")] //string.match is not implemented
     //[TestCase("tests-lua/sort.lua")] //check for "invalid order function" is not implemented
     //[TestCase("tests-lua/sort.lua")] //check for "invalid order function" is not implemented
     //[TestCase("tests-lua/calls.lua")] //  string.dump and reader function for load chunk is not implemented
     //[TestCase("tests-lua/calls.lua")] //  string.dump and reader function for load chunk is not implemented
     [TestCase("tests-lua/closure.lua")]
     [TestCase("tests-lua/closure.lua")]
+    //[TestCase("tests-lua/errors.lua")] // get table name  if nil is not implemented
     [TestCase("tests-lua/events.lua")]
     [TestCase("tests-lua/events.lua")]
     [TestCase("tests-lua/vararg.lua")]
     [TestCase("tests-lua/vararg.lua")]
     [TestCase("tests-lua/nextvar.lua")]
     [TestCase("tests-lua/nextvar.lua")]