Browse Source

rename: rename LuaFile to LuaFileContent and update related methods

Akeit0 7 months ago
parent
commit
bf1e2d87d8
3 changed files with 19 additions and 19 deletions
  1. 3 3
      src/Lua/ILuaFileManager.cs
  2. 14 14
      src/Lua/LuaFileContent.cs
  3. 2 2
      src/Lua/LuaStateExtensions.cs

+ 3 - 3
src/Lua/ILuaFileManager.cs

@@ -3,7 +3,7 @@
 public interface ILuaFileManager
 public interface ILuaFileManager
 {
 {
     public bool IsReadable(string path);
     public bool IsReadable(string path);
-    public ValueTask<LuaFile> ReadFileAsync(string path, CancellationToken cancellationToken);
+    public ValueTask<LuaFileContent> ReadFileContentAsync(string path, CancellationToken cancellationToken);
     public IStream Open(string path, FileMode mode, FileAccess access);
     public IStream Open(string path, FileMode mode, FileAccess access);
     public void Rename (string oldName, string newName);
     public void Rename (string oldName, string newName);
     public void Remove (string path);
     public void Remove (string path);
@@ -59,10 +59,10 @@ public sealed class SystemFileManager : ILuaFileManager
         }
         }
     }
     }
 
 
-    public ValueTask<LuaFile> ReadFileAsync(string path, CancellationToken cancellationToken)
+    public ValueTask<LuaFileContent> ReadFileContentAsync(string path, CancellationToken cancellationToken)
     {
     {
         var bytes = File.ReadAllBytes(path);
         var bytes = File.ReadAllBytes(path);
-        return new(new LuaFile(bytes));
+        return new(new LuaFileContent(bytes));
     }
     }
 
 
     public IStream Open(string path, FileMode mode, FileAccess access)
     public IStream Open(string path, FileMode mode, FileAccess access)

+ 14 - 14
src/Lua/LuaFile.cs → src/Lua/LuaFileContent.cs

@@ -2,46 +2,46 @@
 
 
 namespace Lua;
 namespace Lua;
 
 
-public enum LuaFileType
+public enum LuaFileContentType
 {
 {
     Text,
     Text,
     Bytes
     Bytes
 }
 }
 
 
-public readonly struct LuaFile : IDisposable
+public readonly struct LuaFileContent : IDisposable
 {
 {
-    public LuaFileType Type => type;
+    public LuaFileContentType Type => type;
 
 
-    readonly LuaFileType type;
+    readonly LuaFileContentType type;
     readonly object referenceValue;
     readonly object referenceValue;
 
 
-    public LuaFile(string text)
+    public LuaFileContent(string text)
     {
     {
-        type = LuaFileType.Text;
+        type = LuaFileContentType.Text;
         referenceValue = text;
         referenceValue = text;
     }
     }
 
 
-    public LuaFile(byte[] bytes)
+    public LuaFileContent(byte[] bytes)
     {
     {
-        type = LuaFileType.Bytes;
+        type = LuaFileContentType.Bytes;
         referenceValue = bytes;
         referenceValue = bytes;
     }
     }
 
 
-    public LuaFile(IMemoryOwner<char> bytes)
+    public LuaFileContent(IMemoryOwner<char> bytes)
     {
     {
-        type = LuaFileType.Text;
+        type = LuaFileContentType.Text;
         referenceValue = bytes;
         referenceValue = bytes;
     }
     }
 
 
-    public LuaFile(IMemoryOwner<byte> bytes)
+    public LuaFileContent(IMemoryOwner<byte> bytes)
     {
     {
-        type = LuaFileType.Bytes;
+        type = LuaFileContentType.Bytes;
         referenceValue = bytes;
         referenceValue = bytes;
     }
     }
 
 
     public ReadOnlySpan<char> ReadText()
     public ReadOnlySpan<char> ReadText()
     {
     {
-        if (type != LuaFileType.Text) throw new Exception(); // TODO: add message
+        if (type != LuaFileContentType.Text) throw new Exception(); // TODO: add message
         if (referenceValue is IMemoryOwner<char> mem)
         if (referenceValue is IMemoryOwner<char> mem)
         {
         {
             return mem.Memory.Span;
             return mem.Memory.Span;
@@ -52,7 +52,7 @@ public readonly struct LuaFile : IDisposable
 
 
     public ReadOnlySpan<byte> ReadBytes()
     public ReadOnlySpan<byte> ReadBytes()
     {
     {
-        if (type != LuaFileType.Bytes) throw new Exception(); // TODO: add message
+        if (type != LuaFileContentType.Bytes) throw new Exception(); // TODO: add message
         if (referenceValue is IMemoryOwner<byte> mem)
         if (referenceValue is IMemoryOwner<byte> mem)
         {
         {
             return mem.Memory.Span;
             return mem.Memory.Span;

+ 2 - 2
src/Lua/LuaStateExtensions.cs

@@ -29,8 +29,8 @@ public static class LuaStateExtensions
         var name = "@" + fileName;
         var name = "@" + fileName;
         LuaClosure closure;
         LuaClosure closure;
         {
         {
-            using var file = await state.FileManager.ReadFileAsync(fileName, cancellationToken);
-            closure = file.Type == LuaFileType.Bytes
+            using var file = await state.FileManager.ReadFileContentAsync(fileName, cancellationToken);
+            closure = file.Type == LuaFileContentType.Bytes
                 ? state.Load(file.ReadBytes(), name, mode, environment)
                 ? state.Load(file.ReadBytes(), name, mode, environment)
                 : state.Load(file.ReadText(), name, environment);
                 : state.Load(file.ReadText(), name, environment);
         }
         }