Browse Source

refactor: add sealed, static, etc.

nuskey8 1 month ago
parent
commit
bb3d078d33

+ 1 - 2
src/Lua/Exceptions.cs

@@ -1,9 +1,8 @@
+using System.Runtime.CompilerServices;
 using Lua.CodeAnalysis;
 using Lua.CodeAnalysis;
 using Lua.CodeAnalysis.Syntax;
 using Lua.CodeAnalysis.Syntax;
 using Lua.Internal;
 using Lua.Internal;
 using Lua.Runtime;
 using Lua.Runtime;
-using System.Diagnostics;
-using System.Runtime.CompilerServices;
 
 
 namespace Lua;
 namespace Lua;
 
 

+ 1 - 2
src/Lua/IO/LuaStream.cs

@@ -3,7 +3,7 @@ using System.Text;
 
 
 namespace Lua.IO;
 namespace Lua.IO;
 
 
-sealed class LuaStream(LuaFileOpenMode mode, Stream innerStream) : ILuaStream
+public sealed class LuaStream(LuaFileOpenMode mode, Stream innerStream) : ILuaStream
 {
 {
     Utf8Reader? reader;
     Utf8Reader? reader;
     ulong flushSize = ulong.MaxValue;
     ulong flushSize = ulong.MaxValue;
@@ -53,7 +53,6 @@ sealed class LuaStream(LuaFileOpenMode mode, Stream innerStream) : ILuaStream
         return new(result);
         return new(result);
     }
     }
 
 
-
     public ValueTask WriteAsync(ReadOnlyMemory<char> buffer, CancellationToken cancellationToken)
     public ValueTask WriteAsync(ReadOnlyMemory<char> buffer, CancellationToken cancellationToken)
     {
     {
         if (mode.IsAppend())
         if (mode.IsAppend())

+ 1 - 1
src/Lua/IO/NumberReaderHelper.cs

@@ -3,7 +3,7 @@ using System.Globalization;
 
 
 namespace Lua.IO;
 namespace Lua.IO;
 
 
-public static class NumberReaderHelper
+internal static class NumberReaderHelper
 {
 {
     /// <summary>
     /// <summary>
     /// Scans a span of characters to find the extent of a valid number.
     /// Scans a span of characters to find the extent of a valid number.

+ 1 - 1
src/Lua/Internal/Utf16StringMemoryComparer.cs

@@ -3,7 +3,7 @@ using System.Runtime.InteropServices;
 
 
 namespace Lua.Internal;
 namespace Lua.Internal;
 
 
-public sealed class Utf16StringMemoryComparer : IEqualityComparer<ReadOnlyMemory<char>>
+internal sealed class Utf16StringMemoryComparer : IEqualityComparer<ReadOnlyMemory<char>>
 {
 {
     public static readonly Utf16StringMemoryComparer Default = new();
     public static readonly Utf16StringMemoryComparer Default = new();
 
 

+ 1 - 1
src/Lua/LuaStateExtensions.cs

@@ -1,6 +1,6 @@
+using System.Runtime.CompilerServices;
 using Lua.IO;
 using Lua.IO;
 using Lua.Runtime;
 using Lua.Runtime;
-using System.Runtime.CompilerServices;
 
 
 // ReSharper disable MethodHasAsyncOverloadWithCancellation
 // ReSharper disable MethodHasAsyncOverloadWithCancellation
 
 

+ 1 - 1
src/Lua/LuaTable.cs

@@ -1,6 +1,6 @@
 using System.Runtime.CompilerServices;
 using System.Runtime.CompilerServices;
-using Lua.Internal;
 using System.Collections;
 using System.Collections;
+using Lua.Internal;
 
 
 namespace Lua;
 namespace Lua;
 
 

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

@@ -1,11 +1,10 @@
-using Lua.CodeAnalysis;
-using System.Runtime.CompilerServices;
+using System.Runtime.CompilerServices;
 using Lua.Runtime;
 using Lua.Runtime;
 using Lua.Internal;
 using Lua.Internal;
 
 
 namespace Lua.Standard;
 namespace Lua.Standard;
 
 
-public class DebugLibrary
+public sealed class DebugLibrary
 {
 {
     public static readonly DebugLibrary Instance = new();
     public static readonly DebugLibrary Instance = new();
 
 

+ 1 - 1
src/Lua/Standard/FileHandle.cs

@@ -4,7 +4,7 @@ using Lua.Standard.Internal;
 
 
 namespace Lua.Standard;
 namespace Lua.Standard;
 
 
-public class FileHandle : ILuaUserData
+public sealed class FileHandle : ILuaUserData
 {
 {
     public static readonly LuaFunction IndexMetamethod = new("index", (context, ct) =>
     public static readonly LuaFunction IndexMetamethod = new("index", (context, ct) =>
     {
     {

+ 1 - 1
src/Lua/Standard/Internal/ConsoleHelper.cs

@@ -1,6 +1,6 @@
 namespace Lua.Standard.Internal;
 namespace Lua.Standard.Internal;
 
 
-public class ConsoleHelper
+static class ConsoleHelper
 {
 {
     public static bool SupportStandardConsole => LuaPlatformUtility.IsSandBox;
     public static bool SupportStandardConsole => LuaPlatformUtility.IsSandBox;
 
 

+ 3 - 4
src/Lua/Standard/Internal/LuaPlatformUtility.cs

@@ -1,12 +1,11 @@
 namespace Lua.Standard.Internal;
 namespace Lua.Standard.Internal;
 
 
-class LuaPlatformUtility
+static class LuaPlatformUtility
 {
 {
     public static bool IsSandBox => SupportStdio;
     public static bool IsSandBox => SupportStdio;
+    public static bool SupportStdio => supportStdioTryLazy.Value;
 
 
-    public static bool SupportStdio => _supportStdioTryLazy.Value;
-
-    static Lazy<bool> _supportStdioTryLazy = new(() =>
+    static Lazy<bool> supportStdioTryLazy = new(() =>
     {
     {
         try
         try
         {
         {

+ 1 - 3
src/Lua/Standard/Internal/MatchState.cs

@@ -1,8 +1,6 @@
-using System.Buffers;
-
 namespace Lua.Standard.Internal;
 namespace Lua.Standard.Internal;
 
 
-class MatchState(LuaState state, string source, string pattern)
+sealed class MatchState(LuaState state, string source, string pattern)
 {
 {
     internal const int LuaMaxCaptures = 32;
     internal const int LuaMaxCaptures = 32;
     const int CapUnfinished = -1;
     const int CapUnfinished = -1;

+ 0 - 2
src/Lua/Standard/ModuleLibrary.cs

@@ -1,5 +1,3 @@
-using Lua.Runtime;
-
 namespace Lua.Standard;
 namespace Lua.Standard;
 
 
 public sealed class ModuleLibrary
 public sealed class ModuleLibrary

+ 2 - 2
src/Lua/Standard/StringLibrary.cs

@@ -1,9 +1,9 @@
 using System.Text;
 using System.Text;
+using System.Globalization;
+using System.Diagnostics;
 using Lua.Internal;
 using Lua.Internal;
 using Lua.Runtime;
 using Lua.Runtime;
-using System.Globalization;
 using Lua.Standard.Internal;
 using Lua.Standard.Internal;
-using System.Diagnostics;
 
 
 namespace Lua.Standard;
 namespace Lua.Standard;
 
 

+ 2 - 2
src/Lua/Standard/TableLibrary.cs

@@ -1,7 +1,7 @@
-using Lua.Internal;
 using System.Runtime.CompilerServices;
 using System.Runtime.CompilerServices;
-using Lua.Runtime;
 using System.Globalization;
 using System.Globalization;
+using Lua.Runtime;
+using Lua.Internal;
 
 
 namespace Lua.Standard;
 namespace Lua.Standard;