Browse Source

Rename fields and parameters

Akeit0 7 months ago
parent
commit
d994432c1b

+ 1 - 1
src/Lua/CodeAnalysis/Compilation/Dump.cs

@@ -136,7 +136,7 @@ internal unsafe ref struct DumpState(IBufferWriter<byte> writer, bool reversedEn
         WriteUpValues(prototype.UpValues); //4
         WriteUpValues(prototype.UpValues); //4
 
 
         //Debug
         //Debug
-        WriteString(prototype.Source);
+        WriteString(prototype.ChunkName);
         WriteIntSpanWithLength(prototype.LineInfo);
         WriteIntSpanWithLength(prototype.LineInfo);
         WriteLocalVariables(prototype.LocalVariables);
         WriteLocalVariables(prototype.LocalVariables);
         WriteInt(prototype.UpValues.Length);
         WriteInt(prototype.UpValues.Length);

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

@@ -278,7 +278,7 @@ internal readonly struct LuaDebug : IDisposable
             else
             else
             {
             {
                 var p = cl.Proto;
                 var p = cl.Proto;
-                Source = p.Source;
+                Source = p.ChunkName;
                 LineDefined = p.LineDefined;
                 LineDefined = p.LineDefined;
                 LastLineDefined = p.LastLineDefined;
                 LastLineDefined = p.LastLineDefined;
                 What = (LineDefined==0) ? "main" : "Lua";
                 What = (LineDefined==0) ? "main" : "Lua";

+ 12 - 12
src/Lua/LuaState.cs

@@ -82,8 +82,8 @@ public sealed class LuaState
                 FrameBase = 0,
                 FrameBase = 0,
                 ReturnFrameBase = 0,
                 ReturnFrameBase = 0,
                 SourceLine = null,
                 SourceLine = null,
-                RootChunkName = closure.Proto.Source,
-                ChunkName = closure.Proto.Source,
+                RootChunkName = closure.Proto.ChunkName,
+                ChunkName = closure.Proto.ChunkName,
             }, cancellationToken);
             }, cancellationToken);
 
 
             return new LuaResult(CurrentThread.Stack, 0);
             return new LuaResult(CurrentThread.Stack, 0);
@@ -228,33 +228,33 @@ public sealed class LuaState
     }
     }
 
 
 
 
-    public unsafe LuaClosure Compile(ReadOnlySpan<char> sourceCode, string source,LuaTable? environment = null)
+    public unsafe LuaClosure Compile(ReadOnlySpan<char> chunk, string chunkName,LuaTable? environment = null)
     {
     {
         Prototype prototype;
         Prototype prototype;
-        fixed (char* ptr = sourceCode)
+        fixed (char* ptr = chunk)
         {
         {
-            prototype= Parser.Parse(this, new (ptr,sourceCode.Length), source);
+            prototype= Parser.Parse(this, new (ptr,chunk.Length), chunkName);
         }
         }
         
         
         return new LuaClosure(this, prototype, environment);
         return new LuaClosure(this, prototype, environment);
     }
     }
     
     
-    public LuaClosure Compile(ReadOnlySpan<byte> code, string source , string mode = "bt", LuaTable? environment = null)
+    public LuaClosure Compile(ReadOnlySpan<byte> chunk, string chunkName , string mode = "bt", LuaTable? environment = null)
     {
     {
-        if (code.Length > 4)
+        if (chunk.Length > 4)
         {
         {
-            if (code[0] == '\e')
+            if (chunk[0] == '\e')
             {
             {
-                return new LuaClosure(this,Parser.UnDump(code,source),environment);
+                return new LuaClosure(this,Parser.UnDump(chunk,chunkName),environment);
             }
             }
         }
         }
-        var charCount = Encoding.UTF8.GetCharCount(code);
+        var charCount = Encoding.UTF8.GetCharCount(chunk);
         var pooled = ArrayPool<char>.Shared.Rent(charCount);
         var pooled = ArrayPool<char>.Shared.Rent(charCount);
         try
         try
         {
         {
             var chars = pooled.AsSpan(0, charCount);
             var chars = pooled.AsSpan(0, charCount);
-            Encoding.UTF8.GetChars(code, chars);
-            return Compile(chars, source,environment);
+            Encoding.UTF8.GetChars(chunk, chars);
+            return Compile(chars, chunkName,environment);
         }
         }
         finally
         finally
         {
         {

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

@@ -9,7 +9,7 @@ public sealed class LuaClosure : LuaFunction
     FastListCore<UpValue> upValues;
     FastListCore<UpValue> upValues;
 
 
     public LuaClosure(LuaState state, Prototype proto, LuaTable? environment = null)
     public LuaClosure(LuaState state, Prototype proto, LuaTable? environment = null)
-        : base(proto.Source, static (context, ct) => LuaVirtualMachine.ExecuteClosureAsync(context.State, ct))
+        : base(proto.ChunkName, static (context, ct) => LuaVirtualMachine.ExecuteClosureAsync(context.State, ct))
     {
     {
         Proto = proto;
         Proto = proto;
         if (environment != null)
         if (environment != null)

+ 2 - 2
src/Lua/Runtime/Prototype.cs

@@ -2,7 +2,7 @@ using Lua.CodeAnalysis;
 
 
 namespace Lua.Runtime;
 namespace Lua.Runtime;
 public  sealed  class Prototype(
 public  sealed  class Prototype(
-    string source,
+    string chunkName,
     int lineDefined,
     int lineDefined,
     int lastLineDefined,
     int lastLineDefined,
     int parameterCount,
     int parameterCount,
@@ -24,7 +24,7 @@ public  sealed  class Prototype(
     public ReadOnlySpan<UpValueDesc> UpValues => upValues;
     public ReadOnlySpan<UpValueDesc> UpValues => upValues;
 
 
     //public LuaClosure Cache;
     //public LuaClosure Cache;
-    public readonly string Source = source;
+    public readonly string ChunkName = chunkName;
     public readonly int LineDefined = lineDefined, LastLineDefined = lastLineDefined;
     public readonly int LineDefined = lineDefined, LastLineDefined = lastLineDefined;
     public readonly int ParameterCount = parameterCount,  MaxStackSize = maxStackSize;
     public readonly int ParameterCount = parameterCount,  MaxStackSize = maxStackSize;
     public readonly bool HasVariableArguments = hasVariableArguments;
     public readonly bool HasVariableArguments = hasVariableArguments;

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

@@ -11,7 +11,7 @@ public class Traceback(LuaState state)
     public required LuaClosure 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.Source;
+    internal string RootChunkName => RootFunc.Proto.ChunkName;
     
     
     internal void WriteLastLuaTrace(ref PooledList<char> list )
     internal void WriteLastLuaTrace(ref PooledList<char> list )
     {
     {
@@ -25,7 +25,7 @@ public class Traceback(LuaState state)
             if (!frame.IsTailCall && lastFunc is LuaClosure closure)
             if (!frame.IsTailCall && lastFunc is LuaClosure closure)
             {
             {
                 var p = closure.Proto;
                 var p = closure.Proto;
-                var len = LuaDebug.WriteShortSource(p.Source, shortSourceBuffer);
+                var len = LuaDebug.WriteShortSource(p.ChunkName, shortSourceBuffer);
                 list.AddRange(shortSourceBuffer[..len]);
                 list.AddRange(shortSourceBuffer[..len]);
                 list.AddRange(":");
                 list.AddRange(":");
                 if (p.LineInfo.Length <= frame.CallerInstructionIndex)
                 if (p.LineInfo.Length <= frame.CallerInstructionIndex)
@@ -125,7 +125,7 @@ public class Traceback(LuaState state)
 
 
                 var p = closure.Proto;
                 var p = closure.Proto;
                 list.AddRange("\t");
                 list.AddRange("\t");
-                var len = LuaDebug.WriteShortSource(p.Source, shortSourceBuffer);
+                var len = LuaDebug.WriteShortSource(p.ChunkName, shortSourceBuffer);
                 list.AddRange(shortSourceBuffer[..len]);
                 list.AddRange(shortSourceBuffer[..len]);
                 list.AddRange(":");
                 list.AddRange(":");
                 if (p.LineInfo.Length <= frame.CallerInstructionIndex)
                 if (p.LineInfo.Length <= frame.CallerInstructionIndex)