Browse Source

Fix:: coroutine (return value)

AnnulusGames 1 year ago
parent
commit
dfda22a6fd
1 changed files with 7 additions and 3 deletions
  1. 7 3
      src/Lua/LuaCoroutine.cs

+ 7 - 3
src/Lua/LuaCoroutine.cs

@@ -178,11 +178,15 @@ public sealed class LuaCoroutine : LuaThread, IValueTaskSource<LuaCoroutine.Yiel
                 }
                 }
                 else
                 else
                 {
                 {
-                    ArrayPool<LuaValue>.Shared.Return(this.buffer);
-                    
+                    var resultCount = functionTask!.Result;
+
                     Volatile.Write(ref status, (byte)LuaThreadStatus.Dead);
                     Volatile.Write(ref status, (byte)LuaThreadStatus.Dead);
                     buffer.Span[0] = true;
                     buffer.Span[0] = true;
-                    return 1 + functionTask!.Result;
+                    this.buffer[0..resultCount].CopyTo(buffer.Span[1..]);
+
+                    ArrayPool<LuaValue>.Shared.Return(this.buffer);
+
+                    return 1 + resultCount;
                 }
                 }
             }
             }
             catch (Exception ex) when (ex is not OperationCanceledException)
             catch (Exception ex) when (ex is not OperationCanceledException)