Browse Source

Change: ReadArgument -> GetArgument, HasArgument

AnnulusGames 1 year ago
parent
commit
ef263f89d5
68 changed files with 137 additions and 131 deletions
  1. 8 2
      src/Lua/LuaFunctionExecutionContext.cs
  2. 3 3
      src/Lua/Standard/Basic/AssertFunction.cs
  3. 1 1
      src/Lua/Standard/Basic/DoFileFunction.cs
  4. 1 1
      src/Lua/Standard/Basic/GetMetatableFunction.cs
  5. 1 1
      src/Lua/Standard/Basic/IPairsFunction.cs
  6. 3 3
      src/Lua/Standard/Basic/LoadFileFunction.cs
  7. 5 5
      src/Lua/Standard/Basic/LoadFunction.cs
  8. 2 2
      src/Lua/Standard/Basic/NextFunction.cs
  9. 1 1
      src/Lua/Standard/Basic/PCallFunction.cs
  10. 1 1
      src/Lua/Standard/Basic/PairsFunction.cs
  11. 2 2
      src/Lua/Standard/Basic/RawEqualFunction.cs
  12. 2 2
      src/Lua/Standard/Basic/RawGetFunction.cs
  13. 1 1
      src/Lua/Standard/Basic/RawLenFunction.cs
  14. 3 3
      src/Lua/Standard/Basic/RawSetFunction.cs
  15. 1 1
      src/Lua/Standard/Basic/SelectFunction.cs
  16. 2 2
      src/Lua/Standard/Basic/SetMetatableFunction.cs
  17. 3 3
      src/Lua/Standard/Basic/ToNumberFunction.cs
  18. 1 1
      src/Lua/Standard/Basic/ToStringFunction.cs
  19. 2 2
      src/Lua/Standard/Basic/TypeFunction.cs
  20. 2 2
      src/Lua/Standard/Basic/XPCallFunction.cs
  21. 1 1
      src/Lua/Standard/Coroutines/CoroutineCreateFunction.cs
  22. 1 1
      src/Lua/Standard/Coroutines/CoroutineResumeFunction.cs
  23. 1 1
      src/Lua/Standard/Coroutines/CoroutineStatusFunction.cs
  24. 1 1
      src/Lua/Standard/Coroutines/CoroutineWrapFunction.cs
  25. 2 2
      src/Lua/Standard/IO/CloseFunction.cs
  26. 1 1
      src/Lua/Standard/IO/FileFlushFunction.cs
  27. 2 2
      src/Lua/Standard/IO/FileHandle.cs
  28. 3 3
      src/Lua/Standard/IO/FileLinesFunction.cs
  29. 1 1
      src/Lua/Standard/IO/FileReadFunction.cs
  30. 7 7
      src/Lua/Standard/IO/FileSeekFunction.cs
  31. 4 4
      src/Lua/Standard/IO/FileSetVBufFunction.cs
  32. 1 1
      src/Lua/Standard/IO/FileWriteFunction.cs
  33. 1 1
      src/Lua/Standard/IO/LinesFunction.cs
  34. 3 3
      src/Lua/Standard/IO/OpenFunction.cs
  35. 1 1
      src/Lua/Standard/IO/TypeFunction.cs
  36. 1 1
      src/Lua/Standard/Mathematics/AbsFunction.cs
  37. 1 1
      src/Lua/Standard/Mathematics/AcosFuncion.cs
  38. 1 1
      src/Lua/Standard/Mathematics/AsinFuncion.cs
  39. 2 2
      src/Lua/Standard/Mathematics/Atan2Function.cs
  40. 1 1
      src/Lua/Standard/Mathematics/AtanFuncion.cs
  41. 1 1
      src/Lua/Standard/Mathematics/CeilFuncion.cs
  42. 1 1
      src/Lua/Standard/Mathematics/CosFuncion.cs
  43. 1 1
      src/Lua/Standard/Mathematics/CoshFuncion.cs
  44. 1 1
      src/Lua/Standard/Mathematics/DegFunction.cs
  45. 1 1
      src/Lua/Standard/Mathematics/ExpFuncion.cs
  46. 1 1
      src/Lua/Standard/Mathematics/FloorFuncion.cs
  47. 2 2
      src/Lua/Standard/Mathematics/FmodFunction.cs
  48. 1 1
      src/Lua/Standard/Mathematics/FrexpFunction.cs
  49. 2 2
      src/Lua/Standard/Mathematics/LdexpFunction.cs
  50. 3 3
      src/Lua/Standard/Mathematics/LogFunction.cs
  51. 2 2
      src/Lua/Standard/Mathematics/MaxFunction.cs
  52. 2 2
      src/Lua/Standard/Mathematics/MinFunction.cs
  53. 1 1
      src/Lua/Standard/Mathematics/ModfFunction.cs
  54. 2 2
      src/Lua/Standard/Mathematics/PowFunction.cs
  55. 1 1
      src/Lua/Standard/Mathematics/RadFunction.cs
  56. 3 3
      src/Lua/Standard/Mathematics/RandomFunction.cs
  57. 1 1
      src/Lua/Standard/Mathematics/RandomSeedFunction.cs
  58. 1 1
      src/Lua/Standard/Mathematics/SinFuncion.cs
  59. 1 1
      src/Lua/Standard/Mathematics/SinhFuncion.cs
  60. 1 1
      src/Lua/Standard/Mathematics/SqrtFunction.cs
  61. 1 1
      src/Lua/Standard/Mathematics/TanFunction.cs
  62. 1 1
      src/Lua/Standard/Mathematics/TanhFunction.cs
  63. 1 1
      src/Lua/Standard/Modules/RequireFunction.cs
  64. 7 7
      src/Lua/Standard/Table/ConcatFunction.cs
  65. 6 6
      src/Lua/Standard/Table/InsertFunction.cs
  66. 3 3
      src/Lua/Standard/Table/RemoveFunction.cs
  67. 3 3
      src/Lua/Standard/Table/SortFunction.cs
  68. 5 5
      src/Lua/Standard/Table/UnpackFunction.cs

+ 8 - 2
src/Lua/LuaFunctionExecutionContext.cs

@@ -22,14 +22,20 @@ public readonly record struct LuaFunctionExecutionContext
     }
     }
 
 
     [MethodImpl(MethodImplOptions.AggressiveInlining)]
     [MethodImpl(MethodImplOptions.AggressiveInlining)]
-    public LuaValue ReadArgument(int index)
+    public bool HasArgument(int index)
+    {
+        return ArgumentCount > index && Arguments[index].Type is not LuaValueType.Nil;
+    }
+
+    [MethodImpl(MethodImplOptions.AggressiveInlining)]
+    public LuaValue GetArgument(int index)
     {
     {
         ThrowIfArgumentNotExists(index);
         ThrowIfArgumentNotExists(index);
         return Arguments[index];
         return Arguments[index];
     }
     }
 
 
     [MethodImpl(MethodImplOptions.AggressiveInlining)]
     [MethodImpl(MethodImplOptions.AggressiveInlining)]
-    public T ReadArgument<T>(int index)
+    public T GetArgument<T>(int index)
     {
     {
         ThrowIfArgumentNotExists(index);
         ThrowIfArgumentNotExists(index);
 
 

+ 3 - 3
src/Lua/Standard/Basic/AssertFunction.cs

@@ -7,14 +7,14 @@ public sealed class AssertFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument(0);
+        var arg0 = context.GetArgument(0);
 
 
         if (!arg0.ToBoolean())
         if (!arg0.ToBoolean())
         {
         {
             var message = "assertion failed!";
             var message = "assertion failed!";
-            if (context.ArgumentCount >= 2)
+            if (context.HasArgument(1))
             {
             {
-                message = context.ReadArgument<string>(1);
+                message = context.GetArgument<string>(1);
             }
             }
 
 
             throw new LuaAssertionException(context.State.GetTraceback(), message);
             throw new LuaAssertionException(context.State.GetTraceback(), message);

+ 1 - 1
src/Lua/Standard/Basic/DoFileFunction.cs

@@ -10,7 +10,7 @@ public sealed class DoFileFunction : LuaFunction
 
 
     protected override async ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override async ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<string>(0);
+        var arg0 = context.GetArgument<string>(0);
 
 
         // do not use LuaState.DoFileAsync as it uses the new LuaFunctionExecutionContext
         // do not use LuaState.DoFileAsync as it uses the new LuaFunctionExecutionContext
         var text = await File.ReadAllTextAsync(arg0, cancellationToken);
         var text = await File.ReadAllTextAsync(arg0, cancellationToken);

+ 1 - 1
src/Lua/Standard/Basic/GetMetatableFunction.cs

@@ -10,7 +10,7 @@ public sealed class GetMetatableFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument(0);
+        var arg0 = context.GetArgument(0);
 
 
         if (arg0.TryRead<LuaTable>(out var table))
         if (arg0.TryRead<LuaTable>(out var table))
         {
         {

+ 1 - 1
src/Lua/Standard/Basic/IPairsFunction.cs

@@ -9,7 +9,7 @@ public sealed class IPairsFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<LuaTable>(0);
+        var arg0 = context.GetArgument<LuaTable>(0);
 
 
         // If table has a metamethod __ipairs, calls it with table as argument and returns the first three results from the call.
         // If table has a metamethod __ipairs, calls it with table as argument and returns the first three results from the call.
         if (arg0.Metatable != null && arg0.Metatable.TryGetValue(Metamethods.IPairs, out var metamethod))
         if (arg0.Metatable != null && arg0.Metatable.TryGetValue(Metamethods.IPairs, out var metamethod))

+ 3 - 3
src/Lua/Standard/Basic/LoadFileFunction.cs

@@ -11,9 +11,9 @@ public sealed class LoadFileFunction : LuaFunction
     protected override async ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override async ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
         // Lua-CSharp does not support binary chunks, the mode argument is ignored.
         // Lua-CSharp does not support binary chunks, the mode argument is ignored.
-        var arg0 = context.ReadArgument<string>(0);
-        var arg2 = context.ArgumentCount >= 3
-            ? context.ReadArgument<LuaTable>(2)
+        var arg0 = context.GetArgument<string>(0);
+        var arg2 = context.HasArgument(2)
+            ? context.GetArgument<LuaTable>(2)
             : null;
             : null;
 
 
         // do not use LuaState.DoFileAsync as it uses the new LuaFunctionExecutionContext
         // do not use LuaState.DoFileAsync as it uses the new LuaFunctionExecutionContext

+ 5 - 5
src/Lua/Standard/Basic/LoadFunction.cs

@@ -11,14 +11,14 @@ public sealed class LoadFunction : LuaFunction
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
         // Lua-CSharp does not support binary chunks, the mode argument is ignored.
         // Lua-CSharp does not support binary chunks, the mode argument is ignored.
-        var arg0 = context.ReadArgument(0);
+        var arg0 = context.GetArgument(0);
 
 
-        var arg1 = context.ArgumentCount >= 2
-            ? context.ReadArgument<string>(1)
+        var arg1 = context.HasArgument(1)
+            ? context.GetArgument<string>(1)
             : null;
             : null;
 
 
-        var arg3 = context.ArgumentCount >= 4
-            ? context.ReadArgument<LuaTable>(3)
+        var arg3 = context.HasArgument(3)
+            ? context.GetArgument<LuaTable>(3)
             : null;
             : null;
 
 
         // do not use LuaState.DoFileAsync as it uses the new LuaFunctionExecutionContext
         // do not use LuaState.DoFileAsync as it uses the new LuaFunctionExecutionContext

+ 2 - 2
src/Lua/Standard/Basic/NextFunction.cs

@@ -7,8 +7,8 @@ public sealed class NextFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<LuaTable>(0);
-        var arg1 = context.ArgumentCount >= 2 ? context.Arguments[1] : LuaValue.Nil;
+        var arg0 = context.GetArgument<LuaTable>(0);
+        var arg1 = context.HasArgument(1) ? context.Arguments[1] : LuaValue.Nil;
 
 
         var kv = arg0.GetNext(arg1);
         var kv = arg0.GetNext(arg1);
         buffer.Span[0] = kv.Key;
         buffer.Span[0] = kv.Key;

+ 1 - 1
src/Lua/Standard/Basic/PCallFunction.cs

@@ -9,7 +9,7 @@ public sealed class PCallFunction : LuaFunction
 
 
     protected override async ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override async ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<LuaFunction>(0);
+        var arg0 = context.GetArgument<LuaFunction>(0);
 
 
         try
         try
         {
         {

+ 1 - 1
src/Lua/Standard/Basic/PairsFunction.cs

@@ -9,7 +9,7 @@ public sealed class PairsFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<LuaTable>(0);
+        var arg0 = context.GetArgument<LuaTable>(0);
 
 
         // If table has a metamethod __pairs, calls it with table as argument and returns the first three results from the call.
         // If table has a metamethod __pairs, calls it with table as argument and returns the first three results from the call.
         if (arg0.Metatable != null && arg0.Metatable.TryGetValue(Metamethods.Pairs, out var metamethod))
         if (arg0.Metatable != null && arg0.Metatable.TryGetValue(Metamethods.Pairs, out var metamethod))

+ 2 - 2
src/Lua/Standard/Basic/RawEqualFunction.cs

@@ -8,8 +8,8 @@ public sealed class RawEqualFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument(0);
-        var arg1 = context.ReadArgument(1);
+        var arg0 = context.GetArgument(0);
+        var arg1 = context.GetArgument(1);
 
 
         buffer.Span[0] = arg0 == arg1;
         buffer.Span[0] = arg0 == arg1;
         return new(1);
         return new(1);

+ 2 - 2
src/Lua/Standard/Basic/RawGetFunction.cs

@@ -8,8 +8,8 @@ public sealed class RawGetFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<LuaTable>(0);
-        var arg1 = context.ReadArgument(1);
+        var arg0 = context.GetArgument<LuaTable>(0);
+        var arg1 = context.GetArgument(1);
 
 
         buffer.Span[0] = arg0[arg1];
         buffer.Span[0] = arg0[arg1];
         return new(1);
         return new(1);

+ 1 - 1
src/Lua/Standard/Basic/RawLenFunction.cs

@@ -8,7 +8,7 @@ public sealed class RawLenFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument(0);
+        var arg0 = context.GetArgument(0);
 
 
         if (arg0.TryRead<LuaTable>(out var table))
         if (arg0.TryRead<LuaTable>(out var table))
         {
         {

+ 3 - 3
src/Lua/Standard/Basic/RawSetFunction.cs

@@ -8,9 +8,9 @@ public sealed class RawSetFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<LuaTable>(0);
-        var arg1 = context.ReadArgument(1);
-        var arg2 = context.ReadArgument(2);
+        var arg0 = context.GetArgument<LuaTable>(0);
+        var arg1 = context.GetArgument(1);
+        var arg2 = context.GetArgument(2);
 
 
         arg0[arg1] = arg2;
         arg0[arg1] = arg2;
         return new(0);
         return new(0);

+ 1 - 1
src/Lua/Standard/Basic/SelectFunction.cs

@@ -7,7 +7,7 @@ public sealed class SelectFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument(0);
+        var arg0 = context.GetArgument(0);
 
 
         if (arg0.TryRead<double>(out var d))
         if (arg0.TryRead<double>(out var d))
         {
         {

+ 2 - 2
src/Lua/Standard/Basic/SetMetatableFunction.cs

@@ -10,8 +10,8 @@ public sealed class SetMetatableFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<LuaTable>(0);
-        var arg1 = context.ReadArgument(1);
+        var arg0 = context.GetArgument<LuaTable>(0);
+        var arg1 = context.GetArgument(1);
 
 
         if (arg1.Type is not (LuaValueType.Nil or LuaValueType.Table))
         if (arg1.Type is not (LuaValueType.Nil or LuaValueType.Table))
         {
         {

+ 3 - 3
src/Lua/Standard/Basic/ToNumberFunction.cs

@@ -9,9 +9,9 @@ public sealed class ToNumberFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument(0);
-        var arg1 = context.ArgumentCount >= 2
-            ? (int)context.ReadArgument<double>(1)
+        var arg0 = context.GetArgument(0);
+        var arg1 = context.HasArgument(1)
+            ? (int)context.GetArgument<double>(1)
             : 10;
             : 10;
 
 
         if (arg1 < 2 || arg1 > 36)
         if (arg1 < 2 || arg1 > 36)

+ 1 - 1
src/Lua/Standard/Basic/ToStringFunction.cs

@@ -7,7 +7,7 @@ public sealed class ToStringFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument(0);
+        var arg0 = context.GetArgument(0);
         return arg0.CallToStringAsync(context, buffer, cancellationToken);
         return arg0.CallToStringAsync(context, buffer, cancellationToken);
     }
     }
 }
 }

+ 2 - 2
src/Lua/Standard/Basic/TypeFunction.cs

@@ -7,8 +7,8 @@ public sealed class TypeFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument(0);
-        
+        var arg0 = context.GetArgument(0);
+
         buffer.Span[0] = arg0.Type switch
         buffer.Span[0] = arg0.Type switch
         {
         {
             LuaValueType.Nil => "nil",
             LuaValueType.Nil => "nil",

+ 2 - 2
src/Lua/Standard/Basic/XPCallFunction.cs

@@ -9,8 +9,8 @@ public sealed class XPCallFunction : LuaFunction
 
 
     protected override async ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override async ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<LuaFunction>(0);
-        var arg1 = context.ReadArgument<LuaFunction>(1);
+        var arg0 = context.GetArgument<LuaFunction>(0);
+        var arg1 = context.GetArgument<LuaFunction>(1);
 
 
         using var methodBuffer = new PooledArray<LuaValue>(1024);
         using var methodBuffer = new PooledArray<LuaValue>(1024);
         methodBuffer.AsSpan().Clear();
         methodBuffer.AsSpan().Clear();

+ 1 - 1
src/Lua/Standard/Coroutines/CoroutineCreateFunction.cs

@@ -9,7 +9,7 @@ public sealed class CoroutineCreateFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<LuaFunction>(0);
+        var arg0 = context.GetArgument<LuaFunction>(0);
         buffer.Span[0] = context.State.CreateThread(arg0, true);
         buffer.Span[0] = context.State.CreateThread(arg0, true);
         return new(1);
         return new(1);
     }
     }

+ 1 - 1
src/Lua/Standard/Coroutines/CoroutineResumeFunction.cs

@@ -9,7 +9,7 @@ public sealed class CoroutineResumeFunction : LuaFunction
 
 
     protected override async ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override async ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var thread = context.ReadArgument<LuaThread>(0);
+        var thread = context.GetArgument<LuaThread>(0);
         return await thread.Resume(context, buffer, cancellationToken);
         return await thread.Resume(context, buffer, cancellationToken);
     }
     }
 }
 }

+ 1 - 1
src/Lua/Standard/Coroutines/CoroutineStatusFunction.cs

@@ -9,7 +9,7 @@ public sealed class CoroutineStatusFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var thread = context.ReadArgument<LuaThread>(0);
+        var thread = context.GetArgument<LuaThread>(0);
         buffer.Span[0] = thread.GetStatus() switch
         buffer.Span[0] = thread.GetStatus() switch
         {
         {
             LuaThreadStatus.Normal => "normal",
             LuaThreadStatus.Normal => "normal",

+ 1 - 1
src/Lua/Standard/Coroutines/CoroutineWrapFunction.cs

@@ -9,7 +9,7 @@ public sealed class CoroutineWrapFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<LuaFunction>(0);
+        var arg0 = context.GetArgument<LuaFunction>(0);
         var thread = context.State.CreateThread(arg0, false);
         var thread = context.State.CreateThread(arg0, false);
         buffer.Span[0] = new Wrapper(thread);
         buffer.Span[0] = new Wrapper(thread);
         return new(1);
         return new(1);

+ 2 - 2
src/Lua/Standard/IO/CloseFunction.cs

@@ -7,8 +7,8 @@ public sealed class CloseFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var file = context.ArgumentCount >= 1
-            ? context.ReadArgument<FileHandle>(0)
+        var file = context.HasArgument(0)
+            ? context.GetArgument<FileHandle>(0)
             : context.State.Environment["io"].Read<LuaTable>()["stdout"].Read<FileHandle>();
             : context.State.Environment["io"].Read<LuaTable>()["stdout"].Read<FileHandle>();
 
 
         try
         try

+ 1 - 1
src/Lua/Standard/IO/FileFlushFunction.cs

@@ -7,7 +7,7 @@ public sealed class FileFlushFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var file = context.ReadArgument<FileHandle>(0);
+        var file = context.GetArgument<FileHandle>(0);
 
 
         try
         try
         {
         {

+ 2 - 2
src/Lua/Standard/IO/FileHandle.cs

@@ -10,8 +10,8 @@ public class FileHandle : LuaUserData
     {
     {
         protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
         protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
         {
         {
-            context.ReadArgument<FileHandle>(0);
-            var key = context.ReadArgument(1);
+            context.GetArgument<FileHandle>(0);
+            var key = context.GetArgument(1);
 
 
             if (key.TryRead<string>(out var name))
             if (key.TryRead<string>(out var name))
             {
             {

+ 3 - 3
src/Lua/Standard/IO/FileLinesFunction.cs

@@ -7,11 +7,11 @@ public sealed class FileLinesFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<FileHandle>(0);
-        var arg1 = context.ArgumentCount >= 2
+        var arg0 = context.GetArgument<FileHandle>(0);
+        var arg1 = context.HasArgument(1)
             ? context.Arguments[1]
             ? context.Arguments[1]
             : "*l";
             : "*l";
-        
+
         buffer.Span[0] = new Iterator(arg0, arg1);
         buffer.Span[0] = new Iterator(arg0, arg1);
         return new(1);
         return new(1);
     }
     }

+ 1 - 1
src/Lua/Standard/IO/FileReadFunction.cs

@@ -11,7 +11,7 @@ public sealed class FileReadFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var file = context.ReadArgument<FileHandle>(0);
+        var file = context.GetArgument<FileHandle>(0);
         var resultCount = IOHelper.Read(context.State, file, Name, 1, context.Arguments[1..], buffer, false);
         var resultCount = IOHelper.Read(context.State, file, Name, 1, context.Arguments[1..], buffer, false);
         return new(resultCount);
         return new(resultCount);
     }
     }

+ 7 - 7
src/Lua/Standard/IO/FileSeekFunction.cs

@@ -7,14 +7,14 @@ public sealed class FileSeekFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var file = context.ReadArgument<FileHandle>(0);
-        var whence = context.ArgumentCount >= 2
-            ? context.ReadArgument<string>(1)
+        var file = context.GetArgument<FileHandle>(0);
+        var whence = context.HasArgument(1)
+            ? context.GetArgument<string>(1)
             : "cur";
             : "cur";
-        var offset = context.ArgumentCount >= 3
-            ? context.ReadArgument<double>(2)
+        var offset = context.HasArgument(2)
+            ? context.GetArgument<double>(2)
             : 0;
             : 0;
-        
+
         if (whence is not ("set" or "cur" or "end"))
         if (whence is not ("set" or "cur" or "end"))
         {
         {
             throw new LuaRuntimeException(context.State.GetTraceback(), $"bad argument #2 to 'seek' (invalid option '{whence}')");
             throw new LuaRuntimeException(context.State.GetTraceback(), $"bad argument #2 to 'seek' (invalid option '{whence}')");
@@ -24,7 +24,7 @@ public sealed class FileSeekFunction : LuaFunction
         {
         {
             throw new LuaRuntimeException(context.State.GetTraceback(), $"bad argument #3 to 'seek' (number has no integer representation)");
             throw new LuaRuntimeException(context.State.GetTraceback(), $"bad argument #3 to 'seek' (number has no integer representation)");
         }
         }
-        
+
         try
         try
         {
         {
             buffer.Span[0] = file.Seek(whence, (long)offset);
             buffer.Span[0] = file.Seek(whence, (long)offset);

+ 4 - 4
src/Lua/Standard/IO/FileSetVBufFunction.cs

@@ -7,10 +7,10 @@ public sealed class FileSetVBufFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var file = context.ReadArgument<FileHandle>(0);
-        var mode = context.ReadArgument<string>(1);
-        var size = context.ArgumentCount >= 3
-            ? context.ReadArgument<double>(2)
+        var file = context.GetArgument<FileHandle>(0);
+        var mode = context.GetArgument<string>(1);
+        var size = context.HasArgument(2)
+            ? context.GetArgument<double>(2)
             : -1;
             : -1;
 
 
         if (!MathEx.IsInteger(size))
         if (!MathEx.IsInteger(size))

+ 1 - 1
src/Lua/Standard/IO/FileWriteFunction.cs

@@ -7,7 +7,7 @@ public sealed class FileWriteFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var file = context.ReadArgument<FileHandle>(0);
+        var file = context.GetArgument<FileHandle>(0);
         var resultCount = IOHelper.Write(file, Name, context, buffer);
         var resultCount = IOHelper.Write(file, Name, context, buffer);
         return new(resultCount);
         return new(resultCount);
     }
     }

+ 1 - 1
src/Lua/Standard/IO/LinesFunction.cs

@@ -17,7 +17,7 @@ public sealed class LinesFunction : LuaFunction
         }
         }
         else
         else
         {
         {
-            var fileName = context.ReadArgument<string>(0);
+            var fileName = context.GetArgument<string>(0);
 
 
             using var methodBuffer = new PooledArray<LuaValue>(32);
             using var methodBuffer = new PooledArray<LuaValue>(32);
             IOHelper.Open(context.State, fileName, "r", methodBuffer.AsMemory(), true);
             IOHelper.Open(context.State, fileName, "r", methodBuffer.AsMemory(), true);

+ 3 - 3
src/Lua/Standard/IO/OpenFunction.cs

@@ -7,9 +7,9 @@ public sealed class OpenFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var fileName = context.ReadArgument<string>(0);
-        var mode = context.ArgumentCount >= 2
-            ? context.ReadArgument<string>(1)
+        var fileName = context.GetArgument<string>(0);
+        var mode = context.HasArgument(1)
+            ? context.GetArgument<string>(1)
             : "r";
             : "r";
 
 
         var resultCount = IOHelper.Open(context.State, fileName, mode, buffer, false);
         var resultCount = IOHelper.Open(context.State, fileName, mode, buffer, false);

+ 1 - 1
src/Lua/Standard/IO/TypeFunction.cs

@@ -7,7 +7,7 @@ public sealed class TypeFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument(0);
+        var arg0 = context.GetArgument(0);
 
 
         if (arg0.TryRead<FileHandle>(out var file))
         if (arg0.TryRead<FileHandle>(out var file))
         {
         {

+ 1 - 1
src/Lua/Standard/Mathematics/AbsFunction.cs

@@ -9,7 +9,7 @@ public sealed class AbsFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<double>(0);
+        var arg0 = context.GetArgument<double>(0);
         buffer.Span[0] = Math.Abs(arg0);
         buffer.Span[0] = Math.Abs(arg0);
         return new(1);
         return new(1);
     }
     }

+ 1 - 1
src/Lua/Standard/Mathematics/AcosFuncion.cs

@@ -9,7 +9,7 @@ public sealed class AcosFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<double>(0);
+        var arg0 = context.GetArgument<double>(0);
         buffer.Span[0] = Math.Acos(arg0);
         buffer.Span[0] = Math.Acos(arg0);
         return new(1);
         return new(1);
     }
     }

+ 1 - 1
src/Lua/Standard/Mathematics/AsinFuncion.cs

@@ -9,7 +9,7 @@ public sealed class AsinFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<double>(0);
+        var arg0 = context.GetArgument<double>(0);
         buffer.Span[0] = Math.Asin(arg0);
         buffer.Span[0] = Math.Asin(arg0);
         return new(1);
         return new(1);
     }
     }

+ 2 - 2
src/Lua/Standard/Mathematics/Atan2Function.cs

@@ -9,8 +9,8 @@ public sealed class Atan2Function : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<double>(0);
-        var arg1 = context.ReadArgument<double>(1);
+        var arg0 = context.GetArgument<double>(0);
+        var arg1 = context.GetArgument<double>(1);
 
 
         buffer.Span[0] = Math.Atan2(arg0, arg1);
         buffer.Span[0] = Math.Atan2(arg0, arg1);
         return new(1);
         return new(1);

+ 1 - 1
src/Lua/Standard/Mathematics/AtanFuncion.cs

@@ -9,7 +9,7 @@ public sealed class AtanFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<double>(0);
+        var arg0 = context.GetArgument<double>(0);
         buffer.Span[0] = Math.Atan(arg0);
         buffer.Span[0] = Math.Atan(arg0);
         return new(1);
         return new(1);
     }
     }

+ 1 - 1
src/Lua/Standard/Mathematics/CeilFuncion.cs

@@ -9,7 +9,7 @@ public sealed class CeilFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<double>(0);
+        var arg0 = context.GetArgument<double>(0);
         buffer.Span[0] = Math.Ceiling(arg0);
         buffer.Span[0] = Math.Ceiling(arg0);
         return new(1);
         return new(1);
     }
     }

+ 1 - 1
src/Lua/Standard/Mathematics/CosFuncion.cs

@@ -9,7 +9,7 @@ public sealed class CosFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<double>(0);
+        var arg0 = context.GetArgument<double>(0);
         buffer.Span[0] = Math.Cos(arg0);
         buffer.Span[0] = Math.Cos(arg0);
         return new(1);
         return new(1);
     }
     }

+ 1 - 1
src/Lua/Standard/Mathematics/CoshFuncion.cs

@@ -9,7 +9,7 @@ public sealed class CoshFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<double>(0);
+        var arg0 = context.GetArgument<double>(0);
         buffer.Span[0] = Math.Cosh(arg0);
         buffer.Span[0] = Math.Cosh(arg0);
         return new(1);
         return new(1);
     }
     }

+ 1 - 1
src/Lua/Standard/Mathematics/DegFunction.cs

@@ -9,7 +9,7 @@ public sealed class DegFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<double>(0);
+        var arg0 = context.GetArgument<double>(0);
         buffer.Span[0] = arg0 * (180.0 / Math.PI);
         buffer.Span[0] = arg0 * (180.0 / Math.PI);
         return new(1);
         return new(1);
     }
     }

+ 1 - 1
src/Lua/Standard/Mathematics/ExpFuncion.cs

@@ -9,7 +9,7 @@ public sealed class ExpFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<double>(0);
+        var arg0 = context.GetArgument<double>(0);
         buffer.Span[0] = Math.Exp(arg0);
         buffer.Span[0] = Math.Exp(arg0);
         return new(1);
         return new(1);
     }
     }

+ 1 - 1
src/Lua/Standard/Mathematics/FloorFuncion.cs

@@ -9,7 +9,7 @@ public sealed class FloorFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<double>(0);
+        var arg0 = context.GetArgument<double>(0);
         buffer.Span[0] = Math.Floor(arg0);
         buffer.Span[0] = Math.Floor(arg0);
         return new(1);
         return new(1);
     }
     }

+ 2 - 2
src/Lua/Standard/Mathematics/FmodFunction.cs

@@ -9,8 +9,8 @@ public sealed class FmodFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<double>(0);
-        var arg1 = context.ReadArgument<double>(1);
+        var arg0 = context.GetArgument<double>(0);
+        var arg1 = context.GetArgument<double>(1);
         buffer.Span[0] = arg0 % arg1;
         buffer.Span[0] = arg0 % arg1;
         return new(1);
         return new(1);
     }
     }

+ 1 - 1
src/Lua/Standard/Mathematics/FrexpFunction.cs

@@ -9,7 +9,7 @@ public sealed class FrexpFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<double>(0);
+        var arg0 = context.GetArgument<double>(0);
 
 
         var (m, e) = MathEx.Frexp(arg0);
         var (m, e) = MathEx.Frexp(arg0);
         buffer.Span[0] = m;
         buffer.Span[0] = m;

+ 2 - 2
src/Lua/Standard/Mathematics/LdexpFunction.cs

@@ -9,8 +9,8 @@ public sealed class LdexpFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<double>(0);
-        var arg1 = context.ReadArgument<double>(1);
+        var arg0 = context.GetArgument<double>(0);
+        var arg1 = context.GetArgument<double>(1);
 
 
         buffer.Span[0] = arg0 * Math.Pow(2, arg1);
         buffer.Span[0] = arg0 * Math.Pow(2, arg1);
         return new(1);
         return new(1);

+ 3 - 3
src/Lua/Standard/Mathematics/LogFunction.cs

@@ -9,7 +9,7 @@ public sealed class LogFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<double>(0);
+        var arg0 = context.GetArgument<double>(0);
 
 
         if (context.ArgumentCount == 1)
         if (context.ArgumentCount == 1)
         {
         {
@@ -17,10 +17,10 @@ public sealed class LogFunction : LuaFunction
         }
         }
         else
         else
         {
         {
-            var arg1 = context.ReadArgument<double>(1);
+            var arg1 = context.GetArgument<double>(1);
             buffer.Span[0] = Math.Log(arg0, arg1);
             buffer.Span[0] = Math.Log(arg0, arg1);
         }
         }
-        
+
         return new(1);
         return new(1);
     }
     }
 }
 }

+ 2 - 2
src/Lua/Standard/Mathematics/MaxFunction.cs

@@ -9,10 +9,10 @@ public sealed class MaxFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var x = context.ReadArgument<double>(0);
+        var x = context.GetArgument<double>(0);
         for (int i = 1; i < context.ArgumentCount; i++)
         for (int i = 1; i < context.ArgumentCount; i++)
         {
         {
-            x = Math.Max(x, context.ReadArgument<double>(i));
+            x = Math.Max(x, context.GetArgument<double>(i));
         }
         }
 
 
         buffer.Span[0] = x;
         buffer.Span[0] = x;

+ 2 - 2
src/Lua/Standard/Mathematics/MinFunction.cs

@@ -9,10 +9,10 @@ public sealed class MinFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var x = context.ReadArgument<double>(0);
+        var x = context.GetArgument<double>(0);
         for (int i = 1; i < context.ArgumentCount; i++)
         for (int i = 1; i < context.ArgumentCount; i++)
         {
         {
-            x = Math.Min(x, context.ReadArgument<double>(i));
+            x = Math.Min(x, context.GetArgument<double>(i));
         }
         }
 
 
         buffer.Span[0] = x;
         buffer.Span[0] = x;

+ 1 - 1
src/Lua/Standard/Mathematics/ModfFunction.cs

@@ -9,7 +9,7 @@ public sealed class ModfFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<double>(0);
+        var arg0 = context.GetArgument<double>(0);
         var (i, f) = MathEx.Modf(arg0);
         var (i, f) = MathEx.Modf(arg0);
         buffer.Span[0] = i;
         buffer.Span[0] = i;
         buffer.Span[1] = f;
         buffer.Span[1] = f;

+ 2 - 2
src/Lua/Standard/Mathematics/PowFunction.cs

@@ -9,8 +9,8 @@ public sealed class PowFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<double>(0);
-        var arg1 = context.ReadArgument<double>(1);
+        var arg0 = context.GetArgument<double>(0);
+        var arg1 = context.GetArgument<double>(1);
 
 
         buffer.Span[0] = Math.Pow(arg0, arg1);
         buffer.Span[0] = Math.Pow(arg0, arg1);
         return new(1);
         return new(1);

+ 1 - 1
src/Lua/Standard/Mathematics/RadFunction.cs

@@ -9,7 +9,7 @@ public sealed class RadFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<double>(0);
+        var arg0 = context.GetArgument<double>(0);
         buffer.Span[0] = arg0 * (Math.PI / 180.0);
         buffer.Span[0] = arg0 * (Math.PI / 180.0);
         return new(1);
         return new(1);
     }
     }

+ 3 - 3
src/Lua/Standard/Mathematics/RandomFunction.cs

@@ -18,13 +18,13 @@ public sealed class RandomFunction : LuaFunction
         }
         }
         else if (context.ArgumentCount == 1)
         else if (context.ArgumentCount == 1)
         {
         {
-            var arg0 = context.ReadArgument<double>(0);
+            var arg0 = context.GetArgument<double>(0);
             buffer.Span[0] = rand.NextDouble() * (arg0 - 1) + 1;
             buffer.Span[0] = rand.NextDouble() * (arg0 - 1) + 1;
         }
         }
         else
         else
         {
         {
-            var arg0 = context.ReadArgument<double>(0);
-            var arg1 = context.ReadArgument<double>(1);
+            var arg0 = context.GetArgument<double>(0);
+            var arg1 = context.GetArgument<double>(1);
             buffer.Span[0] = rand.NextDouble() * (arg1 - arg0) + arg0;
             buffer.Span[0] = rand.NextDouble() * (arg1 - arg0) + arg0;
         }
         }
 
 

+ 1 - 1
src/Lua/Standard/Mathematics/RandomSeedFunction.cs

@@ -9,7 +9,7 @@ public sealed class RandomSeedFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<double>(0);
+        var arg0 = context.GetArgument<double>(0);
         context.State.Environment[RandomFunction.RandomInstanceKey] = new LuaUserData<Random>(new Random((int)BitConverter.DoubleToInt64Bits(arg0)));
         context.State.Environment[RandomFunction.RandomInstanceKey] = new LuaUserData<Random>(new Random((int)BitConverter.DoubleToInt64Bits(arg0)));
         return new(0);
         return new(0);
     }
     }

+ 1 - 1
src/Lua/Standard/Mathematics/SinFuncion.cs

@@ -9,7 +9,7 @@ public sealed class SinFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<double>(0);
+        var arg0 = context.GetArgument<double>(0);
         buffer.Span[0] = Math.Sin(arg0);
         buffer.Span[0] = Math.Sin(arg0);
         return new(1);
         return new(1);
     }
     }

+ 1 - 1
src/Lua/Standard/Mathematics/SinhFuncion.cs

@@ -8,7 +8,7 @@ public sealed class SinhFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<double>(0);
+        var arg0 = context.GetArgument<double>(0);
         buffer.Span[0] = Math.Sinh(arg0);
         buffer.Span[0] = Math.Sinh(arg0);
         return new(1);
         return new(1);
     }
     }

+ 1 - 1
src/Lua/Standard/Mathematics/SqrtFunction.cs

@@ -9,7 +9,7 @@ public sealed class SqrtFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<double>(0);
+        var arg0 = context.GetArgument<double>(0);
         buffer.Span[0] = Math.Sqrt(arg0);
         buffer.Span[0] = Math.Sqrt(arg0);
         return new(1);
         return new(1);
     }
     }

+ 1 - 1
src/Lua/Standard/Mathematics/TanFunction.cs

@@ -9,7 +9,7 @@ public sealed class TanFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<double>(0);
+        var arg0 = context.GetArgument<double>(0);
         buffer.Span[0] = Math.Tan(arg0);
         buffer.Span[0] = Math.Tan(arg0);
         return new(1);
         return new(1);
     }
     }

+ 1 - 1
src/Lua/Standard/Mathematics/TanhFunction.cs

@@ -9,7 +9,7 @@ public sealed class TanhFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<double>(0);
+        var arg0 = context.GetArgument<double>(0);
         buffer.Span[0] = Math.Tanh(arg0);
         buffer.Span[0] = Math.Tanh(arg0);
         return new(1);
         return new(1);
     }
     }

+ 1 - 1
src/Lua/Standard/Modules/RequireFunction.cs

@@ -12,7 +12,7 @@ public sealed class RequireFunction : LuaFunction
 
 
     protected override async ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override async ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<string>(0);
+        var arg0 = context.GetArgument<string>(0);
         var loaded = context.State.Environment["package"].Read<LuaTable>()["loaded"].Read<LuaTable>();
         var loaded = context.State.Environment["package"].Read<LuaTable>()["loaded"].Read<LuaTable>();
 
 
         if (!loaded.TryGetValue(arg0, out var loadedTable))
         if (!loaded.TryGetValue(arg0, out var loadedTable))

+ 7 - 7
src/Lua/Standard/Table/ConcatFunction.cs

@@ -9,15 +9,15 @@ public sealed class ConcatFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<LuaTable>(0);
-        var arg1 = context.ArgumentCount >= 2
-            ? context.ReadArgument<string>(1)
+        var arg0 = context.GetArgument<LuaTable>(0);
+        var arg1 = context.HasArgument(1)
+            ? context.GetArgument<string>(1)
             : "";
             : "";
-        var arg2 = context.ArgumentCount >= 3
-            ? (int)context.ReadArgument<double>(2)
+        var arg2 = context.HasArgument(2)
+            ? (int)context.GetArgument<double>(2)
             : 1;
             : 1;
-        var arg3 = context.ArgumentCount >= 4
-            ? (int)context.ReadArgument<double>(3)
+        var arg3 = context.HasArgument(3)
+            ? (int)context.GetArgument<double>(3)
             : arg0.ArrayLength;
             : arg0.ArrayLength;
 
 
         var builder = new ValueStringBuilder(512);
         var builder = new ValueStringBuilder(512);

+ 6 - 6
src/Lua/Standard/Table/InsertFunction.cs

@@ -7,14 +7,14 @@ public sealed class InsertFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var table = context.ReadArgument<LuaTable>(0);
+        var table = context.GetArgument<LuaTable>(0);
 
 
-        var value = context.ArgumentCount >= 3
-            ? context.ReadArgument(2)
-            : context.ReadArgument(1);
+        var value = context.HasArgument(2)
+            ? context.GetArgument(2)
+            : context.GetArgument(1);
 
 
-        var pos = context.ArgumentCount >= 3
-            ? context.ReadArgument<double>(1)
+        var pos = context.HasArgument(2)
+            ? context.GetArgument<double>(1)
             : table.ArrayLength + 1;
             : table.ArrayLength + 1;
 
 
         if (!MathEx.IsInteger(pos))
         if (!MathEx.IsInteger(pos))

+ 3 - 3
src/Lua/Standard/Table/RemoveFunction.cs

@@ -7,9 +7,9 @@ public sealed class RemoveFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<LuaTable>(0);
-        var arg1 = context.ArgumentCount >= 2
-            ? context.ReadArgument<double>(1)
+        var arg0 = context.GetArgument<LuaTable>(0);
+        var arg1 = context.HasArgument(1)
+            ? context.GetArgument<double>(1)
             : arg0.ArrayLength;
             : arg0.ArrayLength;
 
 
         if (!MathEx.IsInteger(arg1))
         if (!MathEx.IsInteger(arg1))

+ 3 - 3
src/Lua/Standard/Table/SortFunction.cs

@@ -31,9 +31,9 @@ public sealed class SortFunction : LuaFunction
 
 
     protected override async ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override async ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<LuaTable>(0);
-        var arg1 = context.ArgumentCount >= 2
-            ? context.ReadArgument<LuaFunction>(1)
+        var arg0 = context.GetArgument<LuaTable>(0);
+        var arg1 = context.HasArgument(1)
+            ? context.GetArgument<LuaFunction>(1)
             : new Closure(context.State, defaultComparer);
             : new Closure(context.State, defaultComparer);
 
 
         await QuickSortAsync(context, arg0.GetArrayMemory(), 0, arg0.ArrayLength - 1, arg1, cancellationToken);
         await QuickSortAsync(context, arg0.GetArrayMemory(), 0, arg0.ArrayLength - 1, arg1, cancellationToken);

+ 5 - 5
src/Lua/Standard/Table/UnpackFunction.cs

@@ -7,12 +7,12 @@ public sealed class UnpackFunction : LuaFunction
 
 
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     protected override ValueTask<int> InvokeAsyncCore(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     {
     {
-        var arg0 = context.ReadArgument<LuaTable>(0);
-        var arg1 = context.ArgumentCount >= 2
-            ? (int)context.ReadArgument<double>(1)
+        var arg0 = context.GetArgument<LuaTable>(0);
+        var arg1 = context.HasArgument(1)
+            ? (int)context.GetArgument<double>(1)
             : 1;
             : 1;
-        var arg2 = context.ArgumentCount >= 3
-            ? (int)context.ReadArgument<double>(2)
+        var arg2 = context.HasArgument(2)
+            ? (int)context.GetArgument<double>(2)
             : arg0.ArrayLength;
             : arg0.ArrayLength;
 
 
         var index = 0;
         var index = 0;