Browse Source

fix: forprep error

Akeit0 6 months ago
parent
commit
d45c971018
2 changed files with 22 additions and 8 deletions
  1. 15 1
      src/Lua/Exceptions.cs
  2. 7 7
      src/Lua/Runtime/LuaVirtualMachine.cs

+ 15 - 1
src/Lua/Exceptions.cs

@@ -372,7 +372,21 @@ public class LuaRuntimeException : Exception, ILuaTracebackBuildable
             return message;
             return message;
         }
         }
 
 
-        return CreateMessage(luaTraceback, message);
+        {
+            var pooledList = new PooledList<char>(64);
+            pooledList.Clear();
+            try
+            {
+                luaTraceback.WriteLastLuaTrace(ref pooledList);
+                if (pooledList.Length != 0) pooledList.AddRange(": ");
+                pooledList.AddRange(message);
+                return pooledList.AsSpan().ToString();
+            }
+            finally
+            {
+                pooledList.Dispose();
+            }
+        }
     }
     }
 
 
     public override string Message
     public override string Message

+ 7 - 7
src/Lua/Runtime/LuaVirtualMachine.cs

@@ -857,12 +857,12 @@ public static partial class LuaVirtualMachine
 
 
     static void ThrowLuaRuntimeException(VirtualMachineExecutionContext context, string message)
     static void ThrowLuaRuntimeException(VirtualMachineExecutionContext context, string message)
     {
     {
-        throw new LuaRuntimeException(context.Thread, message);
+        throw new LuaRuntimeException(GetThreadWithCurrentPc(context), message);
     }
     }
 
 
     static void ThrowLuaNotImplementedException(VirtualMachineExecutionContext context, OpCode opcode)
     static void ThrowLuaNotImplementedException(VirtualMachineExecutionContext context, OpCode opcode)
     {
     {
-        throw new LuaRuntimeException(context.Thread, $"OpCode {opcode} is not implemented");
+        throw new LuaRuntimeException(GetThreadWithCurrentPc(context), $"OpCode {opcode} is not implemented");
     }
     }
 
 
     [MethodImpl(MethodImplOptions.NoInlining)]
     [MethodImpl(MethodImplOptions.NoInlining)]
@@ -1453,12 +1453,12 @@ public static partial class LuaVirtualMachine
         if (c == 0)
         if (c == 0)
         {
         {
             context.Pc++;
             context.Pc++;
-            c =  context.Prototype.Code [context.Pc].Ax;
+            c = context.Prototype.Code[context.Pc].Ax;
         }
         }
 
 
-        table.EnsureArrayCapacity((c-1) * 50 + count);
+        table.EnsureArrayCapacity((c - 1) * 50 + count);
         stack.GetBuffer().Slice(RA + 1, count)
         stack.GetBuffer().Slice(RA + 1, count)
-            .CopyTo(table.GetArraySpan()[((c- 1) * 50)..]);
+            .CopyTo(table.GetArraySpan()[((c - 1) * 50)..]);
         stack.PopUntil(RA + 1);
         stack.PopUntil(RA + 1);
     }
     }
 
 
@@ -1909,7 +1909,7 @@ public static partial class LuaVirtualMachine
             return true;
             return true;
         }
         }
 
 
-        LuaRuntimeException.AttemptInvalidOperationOnLuaStack(GetThreadWithCurrentPc(context), description,context.Pc, context.Instruction.B, context.Instruction.C);
+        LuaRuntimeException.AttemptInvalidOperationOnLuaStack(GetThreadWithCurrentPc(context), description, context.Pc, context.Instruction.B, context.Instruction.C);
         return false;
         return false;
     }
     }
 
 
@@ -2043,7 +2043,7 @@ public static partial class LuaVirtualMachine
             return true;
             return true;
         }
         }
 
 
-        LuaRuntimeException.AttemptInvalidOperationOnLuaStack(GetThreadWithCurrentPc(context), description,context.Pc, context.Instruction.B);
+        LuaRuntimeException.AttemptInvalidOperationOnLuaStack(GetThreadWithCurrentPc(context), description, context.Pc, context.Instruction.B);
         return true;
         return true;
     }
     }