Browse Source

fix: stack overflow error

Akeit0 6 months ago
parent
commit
0c89c0cc83
3 changed files with 11 additions and 2 deletions
  1. 8 0
      src/Lua/Exceptions.cs
  2. 1 1
      src/Lua/Runtime/LuaStack.cs
  3. 2 1
      src/Lua/Standard/BasicLibrary.cs

+ 8 - 0
src/Lua/Exceptions.cs

@@ -68,6 +68,14 @@ public class LuaCompileException(string chunkName, SourcePosition position, int
 
 public class LuaUnDumpException(string message) : Exception(message);
 
+internal class LuaStackOverflowException() : Exception("stack overflow")
+{
+    public override string ToString()
+    {
+        return  "stack overflow";
+    }
+}
+
 internal interface ILuaTracebackBuildable
 {
     Traceback? BuildOrGet();

+ 1 - 1
src/Lua/Runtime/LuaStack.cs

@@ -32,7 +32,7 @@ public sealed class LuaStack(int initialSize = 256)
 
             if (1000000 < size)
             {
-                throw new ("Lua Stack overflow");
+                throw new LuaStackOverflowException();
             }
 
             Array.Resize(ref array, size);

+ 2 - 1
src/Lua/Standard/BasicLibrary.cs

@@ -267,10 +267,11 @@ public sealed class BasicLibrary
                     throw new LuaCanceledException(context.Thread, cancellationToken, ex);
                 case LuaRuntimeException luaEx:
                     {
-                        if (luaEx.ErrorObject.Type != LuaValueType.String)
+                        if (luaEx.InnerException == null && luaEx.ErrorObject.Type != LuaValueType.String)
                         {
                             return context.Return(false, luaEx.ErrorObject);
                         }
+
                         using var builder = new PooledList<char>();
                         var message = luaEx.MinimalMessage();
                         luaEx.Forget();