Browse Source

Fix: print

AnnulusGames 1 year ago
parent
commit
9b6320c697
1 changed files with 6 additions and 4 deletions
  1. 6 4
      src/Lua/Standard/Basic/PrintFunction.cs

+ 6 - 4
src/Lua/Standard/Basic/PrintFunction.cs

@@ -1,3 +1,5 @@
+using Lua.Internal;
+
 namespace Lua.Standard.Basic;
 
 public sealed class PrintFunction : LuaFunction
@@ -5,14 +7,14 @@ public sealed class PrintFunction : LuaFunction
     public override string Name => "print";
     public static readonly PrintFunction Instance = new();
 
-    LuaValue[] buffer = new LuaValue[1];
-
     protected override async ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
+        using var methodBuffer = new PooledArray<LuaValue>(1);
+
         for (int i = 0; i < context.ArgumentCount; i++)
         {
-            await context.Arguments[i].CallToStringAsync(context, this.buffer, cancellationToken);
-            Console.Write(this.buffer[0]);
+            await context.Arguments[i].CallToStringAsync(context, methodBuffer.AsMemory(), cancellationToken);
+            Console.Write(methodBuffer[0]);
             Console.Write('\t');
         }