Browse Source

fix: io registry field naming std -> _IO_

Akeit0 6 months ago
parent
commit
772d71ed14
2 changed files with 13 additions and 14 deletions
  1. 11 11
      src/Lua/Standard/IOLibrary.cs
  2. 2 3
      src/Lua/Standard/OpenLibsExtensions.cs

+ 11 - 11
src/Lua/Standard/IOLibrary.cs

@@ -31,7 +31,7 @@ public sealed class IOLibrary
     {
     {
         var file = context.HasArgument(0)
         var file = context.HasArgument(0)
             ? context.GetArgument<FileHandle>(0)
             ? context.GetArgument<FileHandle>(0)
-            : context.State.Registry["stdout"].Read<FileHandle>();
+            : context.State.Registry["_IO_output"].Read<FileHandle>();
 
 
         try
         try
         {
         {
@@ -46,7 +46,7 @@ public sealed class IOLibrary
 
 
     public async ValueTask<int> Flush(LuaFunctionExecutionContext context, CancellationToken cancellationToken)
     public async ValueTask<int> Flush(LuaFunctionExecutionContext context, CancellationToken cancellationToken)
     {
     {
-        var file = context.State.Registry["stdout"].Read<FileHandle>();
+        var file = context.State.Registry["_IO_output"].Read<FileHandle>();
 
 
         try
         try
         {
         {
@@ -65,20 +65,20 @@ public sealed class IOLibrary
 
 
         if (context.ArgumentCount == 0 || context.Arguments[0].Type is LuaValueType.Nil)
         if (context.ArgumentCount == 0 || context.Arguments[0].Type is LuaValueType.Nil)
         {
         {
-            return new(context.Return(registry["stdin"]));
+            return new(context.Return(registry["_IO_input"]));
         }
         }
 
 
         var arg = context.Arguments[0];
         var arg = context.Arguments[0];
         if (arg.TryRead<FileHandle>(out var file))
         if (arg.TryRead<FileHandle>(out var file))
         {
         {
-            registry["stdin"] = new(file);
+            registry["_IO_input"] = new(file);
             return new(context.Return(new LuaValue(file)));
             return new(context.Return(new LuaValue(file)));
         }
         }
         else
         else
         {
         {
             var stream = context.State.FileSystem.Open(arg.ToString(), LuaFileOpenMode.ReadWriteOpen);
             var stream = context.State.FileSystem.Open(arg.ToString(), LuaFileOpenMode.ReadWriteOpen);
             var handle = new FileHandle(stream);
             var handle = new FileHandle(stream);
-            registry["stdin"] = new(handle);
+            registry["_IO_input"] = new(handle);
             return new(context.Return(new LuaValue(handle)));
             return new(context.Return(new LuaValue(handle)));
         }
         }
     }
     }
@@ -87,7 +87,7 @@ public sealed class IOLibrary
     {
     {
         if (context.ArgumentCount == 0)
         if (context.ArgumentCount == 0)
         {
         {
-            var file = context.State.Registry["stdin"].Read<FileHandle>();
+            var file = context.State.Registry["_IO_input"].Read<FileHandle>();
             return new(context.Return(new CSharpClosure("iterator", [new(file)], static async (context, cancellationToken) =>
             return new(context.Return(new CSharpClosure("iterator", [new(file)], static async (context, cancellationToken) =>
             {
             {
                 var file = context.GetCsClosure()!.UpValues[0].Read<FileHandle>();
                 var file = context.GetCsClosure()!.UpValues[0].Read<FileHandle>();
@@ -156,27 +156,27 @@ public sealed class IOLibrary
 
 
         if (context.ArgumentCount == 0 || context.Arguments[0].Type is LuaValueType.Nil)
         if (context.ArgumentCount == 0 || context.Arguments[0].Type is LuaValueType.Nil)
         {
         {
-            return new(context.Return(io["stdout"]));
+            return new(context.Return(io["_IO_output"]));
         }
         }
 
 
         var arg = context.Arguments[0];
         var arg = context.Arguments[0];
         if (arg.TryRead<FileHandle>(out var file))
         if (arg.TryRead<FileHandle>(out var file))
         {
         {
-            io["stdout"] = new(file);
+            io["_IO_output"] = new(file);
             return new(context.Return(new LuaValue(file)));
             return new(context.Return(new LuaValue(file)));
         }
         }
         else
         else
         {
         {
             var stream = context.State.FileSystem.Open(arg.ToString(), LuaFileOpenMode.ReadWriteOpen);
             var stream = context.State.FileSystem.Open(arg.ToString(), LuaFileOpenMode.ReadWriteOpen);
             var handle = new FileHandle(stream);
             var handle = new FileHandle(stream);
-            io["stdout"] = new(handle);
+            io["_IO_output"] = new(handle);
             return new(context.Return(new LuaValue(handle)));
             return new(context.Return(new LuaValue(handle)));
         }
         }
     }
     }
 
 
     public async ValueTask<int> Read(LuaFunctionExecutionContext context, CancellationToken cancellationToken)
     public async ValueTask<int> Read(LuaFunctionExecutionContext context, CancellationToken cancellationToken)
     {
     {
-        var file = context.State.Registry["stdin"].Read<FileHandle>();
+        var file = context.State.Registry["_IO_input"].Read<FileHandle>();
         var args = context.Arguments.ToArray();
         var args = context.Arguments.ToArray();
         context.Return();
         context.Return();
 
 
@@ -200,7 +200,7 @@ public sealed class IOLibrary
 
 
     public async ValueTask<int> Write(LuaFunctionExecutionContext context, CancellationToken cancellationToken)
     public async ValueTask<int> Write(LuaFunctionExecutionContext context, CancellationToken cancellationToken)
     {
     {
-        var file = context.State.Registry["stdout"].Read<FileHandle>();
+        var file = context.State.Registry["_IO_output"].Read<FileHandle>();
         var resultCount = await IOHelper.WriteAsync(file, "write", context, cancellationToken);
         var resultCount = await IOHelper.WriteAsync(file, "write", context, cancellationToken);
         return resultCount;
         return resultCount;
     }
     }

+ 2 - 3
src/Lua/Standard/OpenLibsExtensions.cs

@@ -51,9 +51,8 @@ public static class OpenLibsExtensions
         var stdin = new LuaValue(new FileHandle(LuaFileOpenMode.Read, ConsoleHelper.OpenStandardInput()));
         var stdin = new LuaValue(new FileHandle(LuaFileOpenMode.Read, ConsoleHelper.OpenStandardInput()));
         var stdout = new LuaValue(new FileHandle(LuaFileOpenMode.Write, ConsoleHelper.OpenStandardOutput()));
         var stdout = new LuaValue(new FileHandle(LuaFileOpenMode.Write, ConsoleHelper.OpenStandardOutput()));
         var stderr = new LuaValue(new FileHandle(LuaFileOpenMode.Write, ConsoleHelper.OpenStandardError()));
         var stderr = new LuaValue(new FileHandle(LuaFileOpenMode.Write, ConsoleHelper.OpenStandardError()));
-        registry["stdin"] = stdin;
-        registry["stdout"] = stdout;
-        registry["stderr"] = stderr;
+        registry["_IO_input"] = stdin;
+        registry["_IO_output"] = stdout;
         io["stdin"] = stdin;
         io["stdin"] = stdin;
         io["stdout"] = stdout;
         io["stdout"] = stdout;
         io["stderr"] = stderr;
         io["stderr"] = stderr;