Browse Source

Rename: Closure to LuaClosure, CsClosure toCSharpClosure

Akeit0 8 months ago
parent
commit
27e348b0a7

+ 3 - 3
src/Lua/Internal/LuaDebug.cs

@@ -198,7 +198,7 @@ internal readonly struct LuaDebug : IDisposable
 
 
         internal bool GetInfo(CallStackFrame? prevFrame, CallStackFrame? frame, LuaFunction function, int pc, ReadOnlySpan<char> what)
         internal bool GetInfo(CallStackFrame? prevFrame, CallStackFrame? frame, LuaFunction function, int pc, ReadOnlySpan<char> what)
         {
         {
-            Closure? closure = function as Closure;
+            LuaClosure? closure = function as LuaClosure;
             int status = 1;
             int status = 1;
             foreach (var c in what)
             foreach (var c in what)
             {
             {
@@ -238,7 +238,7 @@ internal readonly struct LuaDebug : IDisposable
                     case 'n':
                     case 'n':
                         {
                         {
                             /* calling function is a known Lua function? */
                             /* calling function is a known Lua function? */
-                            if (prevFrame is { Function: Closure prevFrameClosure })
+                            if (prevFrame is { Function: LuaClosure prevFrameClosure })
                                 NameWhat = GetFuncName(prevFrameClosure.Proto, frame?.CallerInstructionIndex ?? 0, out Name);
                                 NameWhat = GetFuncName(prevFrameClosure.Proto, frame?.CallerInstructionIndex ?? 0, out Name);
                             else
                             else
                                 NameWhat = null;
                                 NameWhat = null;
@@ -268,7 +268,7 @@ internal readonly struct LuaDebug : IDisposable
 
 
         void GetFuncInfo(LuaFunction f)
         void GetFuncInfo(LuaFunction f)
         {
         {
-            if (f is not Closure cl)
+            if (f is not LuaClosure cl)
             {
             {
                 Source = "=[C#]";
                 Source = "=[C#]";
                 LineDefined = -1;
                 LineDefined = -1;

+ 1 - 1
src/Lua/LuaCoroutine.cs

@@ -214,7 +214,7 @@ public sealed class LuaCoroutine : LuaThread, IValueTaskSource<LuaCoroutine.Yiel
             throw new LuaRuntimeException(context.State.GetTraceback(), "cannot call yield on a coroutine that is not currently running");
             throw new LuaRuntimeException(context.State.GetTraceback(), "cannot call yield on a coroutine that is not currently running");
         }
         }
 
 
-        if (context.Thread.GetCallStackFrames()[^2].Function is not Closure)
+        if (context.Thread.GetCallStackFrames()[^2].Function is not LuaClosure)
         {
         {
             throw new LuaRuntimeException(context.State.GetTraceback(), "attempt to yield across a C#-call boundary");
             throw new LuaRuntimeException(context.State.GetTraceback(), "attempt to yield across a C#-call boundary");
         }
         }

+ 1 - 1
src/Lua/LuaFunction.cs

@@ -17,7 +17,7 @@ public class LuaFunction(string name, Func<LuaFunctionExecutionContext, Memory<L
         var frame = new CallStackFrame
         var frame = new CallStackFrame
         {
         {
             Base = context.FrameBase,
             Base = context.FrameBase,
-            VariableArgumentCount = this is Closure closure ? Math.Max(context.ArgumentCount - closure.Proto.ParameterCount, 0) : 0,
+            VariableArgumentCount = this is LuaClosure closure ? Math.Max(context.ArgumentCount - closure.Proto.ParameterCount, 0) : 0,
             Function = this,
             Function = this,
         };
         };
 
 

+ 2 - 2
src/Lua/LuaFunctionExecutionContext.cs

@@ -116,9 +116,9 @@ public readonly record struct LuaFunctionExecutionContext
         return argValue;
         return argValue;
     }
     }
 
 
-    public CsClosure? GetCsClosure()
+    public CSharpCloasure? GetCsClosure()
     {
     {
-        return Thread.GetCurrentFrame().Function as CsClosure;
+        return Thread.GetCurrentFrame().Function as CSharpCloasure;
     }
     }
 
 
     internal void ThrowBadArgument(int index, string message)
     internal void ThrowBadArgument(int index, string message)

+ 6 - 6
src/Lua/LuaState.cs

@@ -68,7 +68,7 @@ public sealed class LuaState
         Volatile.Write(ref isRunning, true);
         Volatile.Write(ref isRunning, true);
         try
         try
         {
         {
-            var closure = new Closure(this, chunk);
+            var closure = new LuaClosure(this, chunk);
             return await closure.InvokeAsync(new()
             return await closure.InvokeAsync(new()
             {
             {
                 State = this,
                 State = this,
@@ -97,7 +97,7 @@ public sealed class LuaState
         {
         {
             return new(this)
             return new(this)
             {
             {
-                RootFunc = (Closure)MainThread.GetCallStackFrames()[0].Function,
+                RootFunc = (LuaClosure)MainThread.GetCallStackFrames()[0].Function,
                 StackFrames = MainThread.GetCallStackFrames()[1..]
                 StackFrames = MainThread.GetCallStackFrames()[1..]
                     .ToArray()
                     .ToArray()
             };
             };
@@ -120,7 +120,7 @@ public sealed class LuaState
 
 
         return new(this)
         return new(this)
         {
         {
-            RootFunc = (Closure)MainThread.GetCallStackFrames()[0].Function,
+            RootFunc = (LuaClosure)MainThread.GetCallStackFrames()[0].Function,
             StackFrames = list.AsSpan().ToArray()
             StackFrames = list.AsSpan().ToArray()
         };
         };
     }
     }
@@ -132,14 +132,14 @@ public sealed class LuaState
         {
         {
             list.Add(frame);
             list.Add(frame);
         }
         }
-        Closure rootFunc;
-        if (thread.GetCallStackFrames()[0].Function is Closure closure)
+        LuaClosure rootFunc;
+        if (thread.GetCallStackFrames()[0].Function is LuaClosure closure)
         {
         {
             rootFunc = closure;
             rootFunc = closure;
         }
         }
         else
         else
         {
         {
-            rootFunc = (Closure)MainThread.GetCallStackFrames()[0].Function;
+            rootFunc = (LuaClosure)MainThread.GetCallStackFrames()[0].Function;
         }
         }
 
 
         return new(this)
         return new(this)

+ 6 - 0
src/Lua/Runtime/CSharpClosure.cs

@@ -0,0 +1,6 @@
+namespace Lua.Runtime;
+
+public sealed class CSharpCloasure(string name,LuaValue[] upValues,Func<LuaFunctionExecutionContext, Memory<LuaValue>, CancellationToken, ValueTask<int>> func) : LuaFunction(name, func)
+{
+   public readonly LuaValue[] UpValues = upValues;
+}

+ 0 - 6
src/Lua/Runtime/CsClosure.cs

@@ -1,6 +0,0 @@
-namespace Lua.Runtime;
-
-public sealed class CsClosure(string name,LuaValue[] upValues,Func<LuaFunctionExecutionContext, Memory<LuaValue>, CancellationToken, ValueTask<int>> func) : LuaFunction(name, func)
-{
-   public readonly LuaValue[] UpValues = upValues;
-}

+ 3 - 3
src/Lua/Runtime/Closure.cs → src/Lua/Runtime/LuaClosure.cs

@@ -3,12 +3,12 @@ using Lua.Internal;
 
 
 namespace Lua.Runtime;
 namespace Lua.Runtime;
 
 
-public sealed class Closure : LuaFunction
+public sealed class LuaClosure : LuaFunction
 {
 {
     Chunk proto;
     Chunk proto;
     FastListCore<UpValue> upValues;
     FastListCore<UpValue> upValues;
 
 
-    public Closure(LuaState state, Chunk proto, LuaTable? environment = null)
+    public LuaClosure(LuaState state, Chunk proto, LuaTable? environment = null)
         : base(proto.Name, (context, buffer, ct) => LuaVirtualMachine.ExecuteClosureAsync(context.State, buffer, ct))
         : base(proto.Name, (context, buffer, ct) => LuaVirtualMachine.ExecuteClosureAsync(context.State, buffer, ct))
     {
     {
         this.proto = proto;
         this.proto = proto;
@@ -56,7 +56,7 @@ public sealed class Closure : LuaFunction
             return envUpValue;
             return envUpValue;
         }
         }
 
 
-        if (thread.GetCurrentFrame().Function is Closure parentClosure)
+        if (thread.GetCurrentFrame().Function is LuaClosure parentClosure)
         {
         {
             return parentClosure.UpValues[description.Index];
             return parentClosure.UpValues[description.Index];
         }
         }

+ 1 - 1
src/Lua/Runtime/LuaValueRuntimeExtensions.cs

@@ -15,7 +15,7 @@ internal static class LuaRuntimeExtensions
     [MethodImpl(MethodImplOptions.AggressiveInlining)]
     [MethodImpl(MethodImplOptions.AggressiveInlining)]
     public static int GetVariableArgumentCount(this LuaFunction function, int argumentCount)
     public static int GetVariableArgumentCount(this LuaFunction function, int argumentCount)
     {
     {
-        return function is Closure { Proto.HasVariableArguments: true } luaClosure
+        return function is LuaClosure { Proto.HasVariableArguments: true } luaClosure
             ?argumentCount - luaClosure.Proto.ParameterCount
             ?argumentCount - luaClosure.Proto.ParameterCount
             : 0;
             : 0;
     }
     }

+ 2 - 2
src/Lua/Runtime/LuaVirtualMachine.Debug.cs

@@ -43,7 +43,7 @@ public static partial class LuaVirtualMachine
                 var frame = new CallStackFrame
                 var frame = new CallStackFrame
                 {
                 {
                     Base = funcContext.FrameBase,
                     Base = funcContext.FrameBase,
-                    VariableArgumentCount = hook is Closure closure ? Math.Max(funcContext.ArgumentCount - closure.Proto.ParameterCount, 0) : 0,
+                    VariableArgumentCount = hook is LuaClosure closure ? Math.Max(funcContext.ArgumentCount - closure.Proto.ParameterCount, 0) : 0,
                     Function = hook,
                     Function = hook,
                     CallerInstructionIndex = context.Pc,
                     CallerInstructionIndex = context.Pc,
                 };
                 };
@@ -86,7 +86,7 @@ public static partial class LuaVirtualMachine
                     var frame = new CallStackFrame
                     var frame = new CallStackFrame
                     {
                     {
                         Base = funcContext.FrameBase,
                         Base = funcContext.FrameBase,
-                        VariableArgumentCount = hook is Closure closure ? Math.Max(funcContext.ArgumentCount - closure.Proto.ParameterCount, 0) : 0,
+                        VariableArgumentCount = hook is LuaClosure closure ? Math.Max(funcContext.ArgumentCount - closure.Proto.ParameterCount, 0) : 0,
                         Function = hook,
                         Function = hook,
                         CallerInstructionIndex = pc,
                         CallerInstructionIndex = pc,
                     };
                     };

+ 17 - 17
src/Lua/Runtime/LuaVirtualMachine.cs

@@ -22,11 +22,11 @@ public static partial class LuaVirtualMachine
     {
     {
         public readonly LuaState State = state;
         public readonly LuaState State = state;
         public readonly LuaStack Stack = stack;
         public readonly LuaStack Stack = stack;
-        public Closure Closure = (Closure)frame.Function;
+        public LuaClosure LuaClosure = (LuaClosure)frame.Function;
         public readonly LuaValue[] ResultsBuffer = resultsBuffer;
         public readonly LuaValue[] ResultsBuffer = resultsBuffer;
         public readonly Memory<LuaValue> Buffer = buffer;
         public readonly Memory<LuaValue> Buffer = buffer;
         public readonly LuaThread Thread = thread;
         public readonly LuaThread Thread = thread;
-        public Chunk Chunk => Closure.Proto;
+        public Chunk Chunk => LuaClosure.Proto;
         public int FrameBase = frame.Base;
         public int FrameBase = frame.Base;
         public int VariableArgumentCount = frame.VariableArgumentCount;
         public int VariableArgumentCount = frame.VariableArgumentCount;
         public readonly CancellationToken CancellationToken = cancellationToken;
         public readonly CancellationToken CancellationToken = cancellationToken;
@@ -63,7 +63,7 @@ public static partial class LuaVirtualMachine
             Pc = frame.CallerInstructionIndex;
             Pc = frame.CallerInstructionIndex;
             Thread.LastPc = Pc;
             Thread.LastPc = Pc;
             ref readonly var lastFrame = ref frames[^2];
             ref readonly var lastFrame = ref frames[^2];
-            Closure = Unsafe.As<Closure>(lastFrame.Function);
+            LuaClosure = Unsafe.As<LuaClosure>(lastFrame.Function);
             var callInstruction = Chunk.Instructions[Pc];
             var callInstruction = Chunk.Instructions[Pc];
             FrameBase = lastFrame.Base;
             FrameBase = lastFrame.Base;
             VariableArgumentCount = lastFrame.VariableArgumentCount;
             VariableArgumentCount = lastFrame.VariableArgumentCount;
@@ -146,7 +146,7 @@ public static partial class LuaVirtualMachine
         public void Push(in CallStackFrame frame)
         public void Push(in CallStackFrame frame)
         {
         {
             Pc = -1;
             Pc = -1;
-            Closure = (frame.Function as Closure)!;
+            LuaClosure = (frame.Function as LuaClosure)!;
             FrameBase = frame.Base;
             FrameBase = frame.Base;
             VariableArgumentCount = frame.VariableArgumentCount;
             VariableArgumentCount = frame.VariableArgumentCount;
         }
         }
@@ -341,14 +341,14 @@ public static partial class LuaVirtualMachine
                         continue;
                         continue;
                     case OpCode.GetUpVal:
                     case OpCode.GetUpVal:
                         instruction = instructionRef;
                         instruction = instructionRef;
-                        stack.GetWithNotifyTop(instruction.A + frameBase) = context.Closure.GetUpValue(instruction.B);
+                        stack.GetWithNotifyTop(instruction.A + frameBase) = context.LuaClosure.GetUpValue(instruction.B);
                         continue;
                         continue;
                     case OpCode.GetTabUp:
                     case OpCode.GetTabUp:
                     case OpCode.GetTable:
                     case OpCode.GetTable:
                         instruction = instructionRef;
                         instruction = instructionRef;
                         stackHead = ref stack.FastGet(frameBase);
                         stackHead = ref stack.FastGet(frameBase);
                         ref readonly var vc = ref RKC(ref stackHead, ref constHead, instruction);
                         ref readonly var vc = ref RKC(ref stackHead, ref constHead, instruction);
-                        ref readonly var vb = ref (instruction.OpCode == OpCode.GetTable ? ref Unsafe.Add(ref stackHead, instruction.UIntB) : ref context.Closure.GetUpValueRef(instruction.B));
+                        ref readonly var vb = ref (instruction.OpCode == OpCode.GetTable ? ref Unsafe.Add(ref stackHead, instruction.UIntB) : ref context.LuaClosure.GetUpValueRef(instruction.B));
                         var doRestart = false;
                         var doRestart = false;
                         if (vb.TryReadTable(out var luaTable) && luaTable.TryGetValue(vc, out var resultValue) || GetTableValueSlowPath(vb, vc, ref context, out resultValue, out doRestart))
                         if (vb.TryReadTable(out var luaTable) && luaTable.TryGetValue(vc, out var resultValue) || GetTableValueSlowPath(vb, vc, ref context, out resultValue, out doRestart))
                         {
                         {
@@ -371,7 +371,7 @@ public static partial class LuaVirtualMachine
                             }
                             }
                         }
                         }
 
 
-                        var table = context.Closure.GetUpValue(instruction.A);
+                        var table = context.LuaClosure.GetUpValue(instruction.A);
 
 
                         if (table.TryReadTable(out luaTable))
                         if (table.TryReadTable(out luaTable))
                         {
                         {
@@ -394,7 +394,7 @@ public static partial class LuaVirtualMachine
 
 
                     case OpCode.SetUpVal:
                     case OpCode.SetUpVal:
                         instruction = instructionRef;
                         instruction = instructionRef;
-                        context.Closure.SetUpValue(instruction.B, stack.FastGet(instruction.A + frameBase));
+                        context.LuaClosure.SetUpValue(instruction.B, stack.FastGet(instruction.A + frameBase));
                         continue;
                         continue;
                     case OpCode.SetTable:
                     case OpCode.SetTable:
                         instruction = instructionRef;
                         instruction = instructionRef;
@@ -914,7 +914,7 @@ public static partial class LuaVirtualMachine
                         iA = instruction.A;
                         iA = instruction.A;
                         ra1 = iA + frameBase + 1;
                         ra1 = iA + frameBase + 1;
                         stack.EnsureCapacity(ra1);
                         stack.EnsureCapacity(ra1);
-                        stack.Get(ra1 - 1) = new Closure(context.State, context.Chunk.Functions[instruction.SBx]);
+                        stack.Get(ra1 - 1) = new LuaClosure(context.State, context.Chunk.Functions[instruction.SBx]);
                         stack.NotifyTop(ra1);
                         stack.NotifyTop(ra1);
                         continue;
                         continue;
                     case OpCode.VarArg:
                     case OpCode.VarArg:
@@ -1060,7 +1060,7 @@ public static partial class LuaVirtualMachine
             return false;
             return false;
         }
         }
 
 
-        if (func is Closure)
+        if (func is LuaClosure)
         {
         {
             context.Push(newFrame);
             context.Push(newFrame);
             doRestart = true;
             doRestart = true;
@@ -1196,7 +1196,7 @@ public static partial class LuaVirtualMachine
         }
         }
 
 
         context.Push(newFrame);
         context.Push(newFrame);
-        if (func is Closure)
+        if (func is LuaClosure)
         {
         {
             doRestart = true;
             doRestart = true;
             return true;
             return true;
@@ -1246,7 +1246,7 @@ public static partial class LuaVirtualMachine
         stack.NotifyTop(newBase + 2);
         stack.NotifyTop(newBase + 2);
         var newFrame = iterator.CreateNewFrame(ref context, newBase);
         var newFrame = iterator.CreateNewFrame(ref context, newBase);
         context.Thread.PushCallStackFrame(newFrame);
         context.Thread.PushCallStackFrame(newFrame);
-        if (iterator is Closure)
+        if (iterator is LuaClosure)
         {
         {
             context.Push(newFrame);
             context.Push(newFrame);
             doRestart = true;
             doRestart = true;
@@ -1399,7 +1399,7 @@ public static partial class LuaVirtualMachine
             return false;
             return false;
         }
         }
 
 
-        if (indexTable is Closure)
+        if (indexTable is LuaClosure)
         {
         {
             context.Push(newFrame);
             context.Push(newFrame);
             doRestart = true;
             doRestart = true;
@@ -1499,7 +1499,7 @@ public static partial class LuaVirtualMachine
             return false;
             return false;
         }
         }
 
 
-        if (newIndexFunction is Closure)
+        if (newIndexFunction is LuaClosure)
         {
         {
             context.Push(newFrame);
             context.Push(newFrame);
             doRestart = true;
             doRestart = true;
@@ -1553,7 +1553,7 @@ public static partial class LuaVirtualMachine
                 return false;
                 return false;
             }
             }
 
 
-            if (func is Closure)
+            if (func is LuaClosure)
             {
             {
                 context.Push(newFrame);
                 context.Push(newFrame);
                 doRestart = true;
                 doRestart = true;
@@ -1607,7 +1607,7 @@ public static partial class LuaVirtualMachine
                 return false;
                 return false;
             }
             }
 
 
-            if (func is Closure)
+            if (func is LuaClosure)
             {
             {
                 context.Push(newFrame);
                 context.Push(newFrame);
                 doRestart = true;
                 doRestart = true;
@@ -1671,7 +1671,7 @@ public static partial class LuaVirtualMachine
                 doRestart = false;
                 doRestart = false;
                 return false;
                 return false;
             }
             }
-            if (func is Closure)
+            if (func is LuaClosure)
             {
             {
                 context.Push(newFrame);
                 context.Push(newFrame);
                 doRestart = true;
                 doRestart = true;

+ 7 - 7
src/Lua/Runtime/Tracebacks.cs

@@ -8,7 +8,7 @@ namespace Lua.Runtime;
 public class Traceback(LuaState state)
 public class Traceback(LuaState state)
 {
 {
     public LuaState State => state;
     public LuaState State => state;
-    public required Closure RootFunc { get; init; }
+    public required LuaClosure RootFunc { get; init; }
     public required CallStackFrame[] StackFrames { get; init; }
     public required CallStackFrame[] StackFrames { get; init; }
 
 
     internal string RootChunkName => RootFunc.Proto.Name;
     internal string RootChunkName => RootFunc.Proto.Name;
@@ -22,7 +22,7 @@ public class Traceback(LuaState state)
             {
             {
                 LuaFunction lastFunc = index > 0 ? stackFrames[index - 1].Function : RootFunc;
                 LuaFunction lastFunc = index > 0 ? stackFrames[index - 1].Function : RootFunc;
                 var frame = stackFrames[index];
                 var frame = stackFrames[index];
-                if (!frame.IsTailCall && lastFunc is Closure closure)
+                if (!frame.IsTailCall && lastFunc is LuaClosure closure)
                 {
                 {
                     var p = closure.Proto;
                     var p = closure.Proto;
                     if (frame.CallerInstructionIndex < 0 || p.SourcePositions.Length <= frame.CallerInstructionIndex)
                     if (frame.CallerInstructionIndex < 0 || p.SourcePositions.Length <= frame.CallerInstructionIndex)
@@ -54,7 +54,7 @@ public class Traceback(LuaState state)
         return GetTracebackString(State, RootFunc, StackFrames[..^skipFrames], LuaValue.Nil);
         return GetTracebackString(State, RootFunc, StackFrames[..^skipFrames], LuaValue.Nil);
     }
     }
 
 
-    internal static string GetTracebackString(LuaState state, Closure rootFunc, ReadOnlySpan<CallStackFrame> stackFrames, LuaValue message, bool skipFirstCsharpCall = false)
+    internal static string GetTracebackString(LuaState state, LuaClosure rootFunc, ReadOnlySpan<CallStackFrame> stackFrames, LuaValue message, bool skipFirstCsharpCall = false)
     {
     {
         using var list = new PooledList<char>(64);
         using var list = new PooledList<char>(64);
         if (message.Type is not LuaValueType.Nil)
         if (message.Type is not LuaValueType.Nil)
@@ -67,7 +67,7 @@ public class Traceback(LuaState state)
         var intFormatBuffer = (stackalloc char[15]);
         var intFormatBuffer = (stackalloc char[15]);
         var shortSourceBuffer = (stackalloc char[59]);
         var shortSourceBuffer = (stackalloc char[59]);
         {
         {
-            if (0 < stackFrames.Length && !skipFirstCsharpCall && stackFrames[^1].Function is { } f and not Closure)
+            if (0 < stackFrames.Length && !skipFirstCsharpCall && stackFrames[^1].Function is { } f and not LuaClosure)
             {
             {
                 list.AddRange("\t[C#]: in function '");
                 list.AddRange("\t[C#]: in function '");
                 list.AddRange(f.Name);
                 list.AddRange(f.Name);
@@ -78,13 +78,13 @@ public class Traceback(LuaState state)
         for (var index = stackFrames.Length - 1; index >= 0; index--)
         for (var index = stackFrames.Length - 1; index >= 0; index--)
         {
         {
             LuaFunction lastFunc = index > 0 ? stackFrames[index - 1].Function : rootFunc;
             LuaFunction lastFunc = index > 0 ? stackFrames[index - 1].Function : rootFunc;
-            if (lastFunc is not null and not Closure)
+            if (lastFunc is not null and not LuaClosure)
             {
             {
                 list.AddRange("\t[C#]: in function '");
                 list.AddRange("\t[C#]: in function '");
                 list.AddRange(lastFunc.Name);
                 list.AddRange(lastFunc.Name);
                 list.AddRange("'\n");
                 list.AddRange("'\n");
             }
             }
-            else if (lastFunc is Closure closure)
+            else if (lastFunc is LuaClosure closure)
             {
             {
                 var frame = stackFrames[index];
                 var frame = stackFrames[index];
 
 
@@ -141,7 +141,7 @@ public class Traceback(LuaState state)
                 }
                 }
 
 
                 var caller = index > 1 ? stackFrames[index - 2].Function : rootFunc;
                 var caller = index > 1 ? stackFrames[index - 2].Function : rootFunc;
-                if (index > 0 && caller is Closure callerClosure)
+                if (index > 0 && caller is LuaClosure callerClosure)
                 {
                 {
                     var t = LuaDebug.GetFuncName(callerClosure.Proto, stackFrames[index - 1].CallerInstructionIndex, out var name);
                     var t = LuaDebug.GetFuncName(callerClosure.Proto, stackFrames[index - 1].CallerInstructionIndex, out var name);
                     if (t is not null)
                     if (t is not null)

+ 3 - 3
src/Lua/Standard/BasicLibrary.cs

@@ -97,7 +97,7 @@ public sealed class BasicLibrary
         var fileName = Path.GetFileName(arg0);
         var fileName = Path.GetFileName(arg0);
         var chunk = LuaCompiler.Default.Compile(text, "@"+fileName);
         var chunk = LuaCompiler.Default.Compile(text, "@"+fileName);
 
 
-        return await new Closure(context.State, chunk).InvokeAsync(context, buffer, cancellationToken);
+        return await new LuaClosure(context.State, chunk).InvokeAsync(context, buffer, cancellationToken);
     }
     }
 
 
     public ValueTask<int> Error(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
     public ValueTask<int> Error(LuaFunctionExecutionContext context, Memory<LuaValue> buffer, CancellationToken cancellationToken)
@@ -182,7 +182,7 @@ public sealed class BasicLibrary
             var text = await File.ReadAllTextAsync(arg0, cancellationToken);
             var text = await File.ReadAllTextAsync(arg0, cancellationToken);
             var fileName = Path.GetFileName(arg0);
             var fileName = Path.GetFileName(arg0);
             var chunk = LuaCompiler.Default.Compile(text, fileName);
             var chunk = LuaCompiler.Default.Compile(text, fileName);
-            buffer.Span[0] = new Closure(context.State, chunk, arg2);
+            buffer.Span[0] = new LuaClosure(context.State, chunk, arg2);
             return 1;
             return 1;
         }
         }
         catch (Exception ex)
         catch (Exception ex)
@@ -212,7 +212,7 @@ public sealed class BasicLibrary
             if (arg0.TryRead<string>(out var str))
             if (arg0.TryRead<string>(out var str))
             {
             {
                 var chunk = LuaCompiler.Default.Compile(str, arg1 ?? str);
                 var chunk = LuaCompiler.Default.Compile(str, arg1 ?? str);
-                buffer.Span[0] = new Closure(context.State, chunk, arg3);
+                buffer.Span[0] = new LuaClosure(context.State, chunk, arg3);
                 return new(1);
                 return new(1);
             }
             }
             else if (arg0.TryRead<LuaFunction>(out var function))
             else if (arg0.TryRead<LuaFunction>(out var function))

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

@@ -59,7 +59,7 @@ public sealed class CoroutineLibrary
         var arg0 = context.GetArgument<LuaFunction>(0);
         var arg0 = context.GetArgument<LuaFunction>(0);
         var thread = new LuaCoroutine(arg0, false);
         var thread = new LuaCoroutine(arg0, false);
 
 
-        buffer.Span[0] = new CsClosure("wrap", [thread],static async (context, buffer, cancellationToken) =>
+        buffer.Span[0] = new CSharpCloasure("wrap", [thread],static async (context, buffer, cancellationToken) =>
         {
         {
             var thread = context.GetCsClosure()!.UpValues[0].Read<LuaThread>();
             var thread = context.GetCsClosure()!.UpValues[0].Read<LuaThread>();
             if (thread is not LuaCoroutine coroutine)
             if (thread is not LuaCoroutine coroutine)

+ 10 - 10
src/Lua/Standard/DebugLibrary.cs

@@ -82,7 +82,7 @@ public class DebugLibrary
         var frameBase = frame.Base;
         var frameBase = frame.Base;
 
 
 
 
-        if (frame.Function is Closure closure)
+        if (frame.Function is LuaClosure closure)
         {
         {
             var locals = closure.Proto.Locals;
             var locals = closure.Proto.Locals;
             var nextFrame = callStack[^level];
             var nextFrame = callStack[^level];
@@ -128,7 +128,7 @@ public class DebugLibrary
     {
     {
         static LuaValue GetParam(LuaFunction function, int index)
         static LuaValue GetParam(LuaFunction function, int index)
         {
         {
-            if (function is Closure closure)
+            if (function is LuaClosure closure)
             {
             {
                 var paramCount = closure.Proto.ParameterCount;
                 var paramCount = closure.Proto.ParameterCount;
                 if (0 <= index && index < paramCount)
                 if (0 <= index && index < paramCount)
@@ -199,9 +199,9 @@ public class DebugLibrary
     {
     {
         var func = context.GetArgument<LuaFunction>(0);
         var func = context.GetArgument<LuaFunction>(0);
         var index = context.GetArgument<int>(1) - 1;
         var index = context.GetArgument<int>(1) - 1;
-        if (func is not Closure closure)
+        if (func is not LuaClosure closure)
         {
         {
-            if (func is CsClosure csClosure)
+            if (func is CSharpCloasure csClosure)
             {
             {
                 var upValues = csClosure.UpValues;
                 var upValues = csClosure.UpValues;
                 if (index < 0 || index >= upValues.Length)
                 if (index < 0 || index >= upValues.Length)
@@ -237,9 +237,9 @@ public class DebugLibrary
         var func = context.GetArgument<LuaFunction>(0);
         var func = context.GetArgument<LuaFunction>(0);
         var index = context.GetArgument<int>(1) - 1;
         var index = context.GetArgument<int>(1) - 1;
         var value = context.GetArgument(2);
         var value = context.GetArgument(2);
-        if (func is not Closure closure)
+        if (func is not LuaClosure closure)
         {
         {
-            if (func is CsClosure csClosure)
+            if (func is CSharpCloasure csClosure)
             {
             {
                 var upValues = csClosure.UpValues;
                 var upValues = csClosure.UpValues;
                 if (index >= 0 && index < upValues.Length)
                 if (index >= 0 && index < upValues.Length)
@@ -380,7 +380,7 @@ public class DebugLibrary
 
 
         var skipCount = Math.Min(Math.Max(level - 1, 0), callStack.Length - 1);
         var skipCount = Math.Min(Math.Max(level - 1, 0), callStack.Length - 1);
         var frames = callStack[1..^skipCount];
         var frames = callStack[1..^skipCount];
-        buffer.Span[0] = Runtime.Traceback.GetTracebackString(context.State, (Closure)callStack[0].Function, frames, message, level == 1);
+        buffer.Span[0] = Runtime.Traceback.GetTracebackString(context.State, (LuaClosure)callStack[0].Function, frames, message, level == 1);
         return new(1);
         return new(1);
     }
     }
 
 
@@ -395,7 +395,7 @@ public class DebugLibrary
         var n1 = context.GetArgument<int>(1);
         var n1 = context.GetArgument<int>(1);
         var f1 = context.GetArgument<LuaFunction>(0);
         var f1 = context.GetArgument<LuaFunction>(0);
 
 
-        if (f1 is not Closure closure)
+        if (f1 is not LuaClosure closure)
         {
         {
             buffer.Span[0] = LuaValue.Nil;
             buffer.Span[0] = LuaValue.Nil;
             return new(1);
             return new(1);
@@ -419,7 +419,7 @@ public class DebugLibrary
         var n1 = context.GetArgument<int>(1);
         var n1 = context.GetArgument<int>(1);
         var f1 = context.GetArgument<LuaFunction>(0);
         var f1 = context.GetArgument<LuaFunction>(0);
 
 
-        if (f1 is not Closure closure1 || f2 is not Closure closure2)
+        if (f1 is not LuaClosure closure1 || f2 is not LuaClosure closure2)
         {
         {
             buffer.Span[0] = LuaValue.Nil;
             buffer.Span[0] = LuaValue.Nil;
             return new(1);
             return new(1);
@@ -633,7 +633,7 @@ public class DebugLibrary
 
 
         if (what.Contains('L'))
         if (what.Contains('L'))
         {
         {
-            if (functionToInspect is Closure closure)
+            if (functionToInspect is LuaClosure closure)
             {
             {
                 var activeLines = new LuaTable(0, 8);
                 var activeLines = new LuaTable(0, 8);
                 foreach (var pos in closure.Proto.SourcePositions)
                 foreach (var pos in closure.Proto.SourcePositions)

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

@@ -177,7 +177,7 @@ public class FileHandle : ILuaUserData
             : "*l";
             : "*l";
 
 
 
 
-        buffer.Span[0] = new CsClosure("iterator", [new (file),format],static (context, buffer, cancellationToken) =>
+        buffer.Span[0] = new CSharpCloasure("iterator", [new (file),format],static (context, buffer, cancellationToken) =>
         {
         {
             var upValues = context.GetCsClosure()!.UpValues.AsSpan();
             var upValues = context.GetCsClosure()!.UpValues.AsSpan();
             var file = upValues[0].Read<FileHandle>();
             var file = upValues[0].Read<FileHandle>();

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

@@ -97,7 +97,7 @@ public sealed class IOLibrary
         if (context.ArgumentCount == 0)
         if (context.ArgumentCount == 0)
         {
         {
             var file = context.State.Environment["io"].Read<LuaTable>()["stdio"].Read<FileHandle>();
             var file = context.State.Environment["io"].Read<LuaTable>()["stdio"].Read<FileHandle>();
-            buffer.Span[0] = new CsClosure("iterator",[new (file)] ,static (context, buffer, ct) =>
+            buffer.Span[0] = new CSharpCloasure("iterator",[new (file)] ,static (context, buffer, ct) =>
             {
             {
                 var file = context.GetCsClosure()!.UpValues[0].Read<FileHandle>();
                 var file = context.GetCsClosure()!.UpValues[0].Read<FileHandle>();
                 var resultCount = IOHelper.Read(context.State, file, "lines", 0, [], buffer, true);
                 var resultCount = IOHelper.Read(context.State, file, "lines", 0, [], buffer, true);
@@ -121,7 +121,7 @@ public sealed class IOLibrary
             upValues[0] = new(file);
             upValues[0] = new(file);
             context.Arguments[1..].CopyTo(upValues[1..]);
             context.Arguments[1..].CopyTo(upValues[1..]);
 
 
-            buffer.Span[0] = new CsClosure("iterator", upValues, static (context, buffer, ct) =>
+            buffer.Span[0] = new CSharpCloasure("iterator", upValues, static (context, buffer, ct) =>
             {
             {
                 var upValues = context.GetCsClosure()!.UpValues;
                 var upValues = context.GetCsClosure()!.UpValues;
                 var file = upValues[0].Read<FileHandle>();
                 var file = upValues[0].Read<FileHandle>();

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

@@ -26,7 +26,7 @@ public sealed class ModuleLibrary
             var chunk = LuaCompiler.Default.Compile(module.ReadText(), module.Name);
             var chunk = LuaCompiler.Default.Compile(module.ReadText(), module.Name);
 
 
             using var methodBuffer = new PooledArray<LuaValue>(1);
             using var methodBuffer = new PooledArray<LuaValue>(1);
-            await new Closure(context.State, chunk).InvokeAsync(context, methodBuffer.AsMemory(), cancellationToken);
+            await new LuaClosure(context.State, chunk).InvokeAsync(context, methodBuffer.AsMemory(), cancellationToken);
 
 
             loadedTable = methodBuffer[0];
             loadedTable = methodBuffer[0];
             loaded[arg0] = loadedTable;
             loaded[arg0] = loadedTable;

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

@@ -432,7 +432,7 @@ public sealed class StringLibrary
         var regex = StringHelper.ToRegex(pattern);
         var regex = StringHelper.ToRegex(pattern);
         var matches = regex.Matches(s);
         var matches = regex.Matches(s);
 
 
-        buffer.Span[0] = new CsClosure("iterator",[new LuaValue(matches),0],static (context, buffer, cancellationToken) =>
+        buffer.Span[0] = new CSharpCloasure("iterator",[new LuaValue(matches),0],static (context, buffer, cancellationToken) =>
         {
         {
             var upValues = context.GetCsClosure()!.UpValues;
             var upValues = context.GetCsClosure()!.UpValues;
             var matches = upValues[0].Read<MatchCollection>();
             var matches = upValues[0].Read<MatchCollection>();

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

@@ -163,7 +163,7 @@ public sealed class TableLibrary
         var arg0 = context.GetArgument<LuaTable>(0);
         var arg0 = context.GetArgument<LuaTable>(0);
         var arg1 = context.HasArgument(1)
         var arg1 = context.HasArgument(1)
             ? context.GetArgument<LuaFunction>(1)
             ? context.GetArgument<LuaFunction>(1)
-            : new Closure(context.State, defaultComparer);
+            : new LuaClosure(context.State, defaultComparer);
         
         
         context.Thread.PushCallStackFrame(new ()
         context.Thread.PushCallStackFrame(new ()
         {
         {