Browse Source

Fix: the chunk name of the generated lua function becomes anonymous

AnnulusGames 1 year ago
parent
commit
3f8785810f
1 changed files with 7 additions and 7 deletions
  1. 7 7
      src/Lua.SourceGenerator/LuaObjectGenerator.Emit.cs

+ 7 - 7
src/Lua.SourceGenerator/LuaObjectGenerator.Emit.cs

@@ -200,7 +200,7 @@ partial class LuaObjectGenerator
 
 
     static bool TryEmitIndexMetamethod(TypeMetadata typeMetadata, CodeBuilder builder, in SourceProductionContext context)
     static bool TryEmitIndexMetamethod(TypeMetadata typeMetadata, CodeBuilder builder, in SourceProductionContext context)
     {
     {
-        builder.AppendLine("static readonly global::Lua.LuaFunction __metamethod_index = new global::Lua.LuaFunction((context, buffer, ct) =>");
+        builder.AppendLine(@"static readonly global::Lua.LuaFunction __metamethod_index = new global::Lua.LuaFunction(""index"", (context, buffer, ct) =>");
 
 
         using (builder.BeginBlockScope())
         using (builder.BeginBlockScope())
         {
         {
@@ -243,7 +243,7 @@ partial class LuaObjectGenerator
 
 
     static bool TryEmitNewIndexMetamethod(TypeMetadata typeMetadata, CodeBuilder builder, in SourceProductionContext context)
     static bool TryEmitNewIndexMetamethod(TypeMetadata typeMetadata, CodeBuilder builder, in SourceProductionContext context)
     {
     {
-        builder.AppendLine("static readonly global::Lua.LuaFunction __metamethod_newindex = new global::Lua.LuaFunction((context, buffer, ct) =>");
+        builder.AppendLine(@"static readonly global::Lua.LuaFunction __metamethod_newindex = new global::Lua.LuaFunction(""newindex"", (context, buffer, ct) =>");
 
 
         using (builder.BeginBlockScope())
         using (builder.BeginBlockScope())
         {
         {
@@ -291,7 +291,7 @@ partial class LuaObjectGenerator
 
 
                 using (builder.BeginIndentScope())
                 using (builder.BeginIndentScope())
                 {
                 {
-                    builder.AppendLine(@$"throw new global::Lua.LuaRuntimeException(context.State.GetTraceback(), $""'{{key}}'  not found."");");
+                    builder.AppendLine(@$"throw new global::Lua.LuaRuntimeException(context.State.GetTraceback(), $""'{{key}}' not found."");");
                 }
                 }
             }
             }
 
 
@@ -314,7 +314,7 @@ partial class LuaObjectGenerator
             if (methodMetadata.HasMemberAttribute)
             if (methodMetadata.HasMemberAttribute)
             {
             {
                 functionName = $"__function_{methodMetadata.LuaMemberName}";
                 functionName = $"__function_{methodMetadata.LuaMemberName}";
-                EmitMethodFunction(functionName, typeMetadata, methodMetadata, builder, references);
+                EmitMethodFunction(functionName, methodMetadata.LuaMemberName, typeMetadata, methodMetadata, builder, references);
             }
             }
 
 
             if (methodMetadata.HasMetamethodAttribute)
             if (methodMetadata.HasMetamethodAttribute)
@@ -333,7 +333,7 @@ partial class LuaObjectGenerator
 
 
                 if (functionName == null)
                 if (functionName == null)
                 {
                 {
-                    EmitMethodFunction($"__metamethod_{methodMetadata.Metamethod}", typeMetadata, methodMetadata, builder, references);
+                    EmitMethodFunction($"__metamethod_{methodMetadata.Metamethod}", methodMetadata.Metamethod.ToString().ToLower(), typeMetadata, methodMetadata, builder, references);
                 }
                 }
                 else
                 else
                 {
                 {
@@ -345,9 +345,9 @@ partial class LuaObjectGenerator
         return true;
         return true;
     }
     }
 
 
-    static void EmitMethodFunction(string functionName, TypeMetadata typeMetadata, MethodMetadata methodMetadata, CodeBuilder builder, SymbolReferences references)
+    static void EmitMethodFunction(string functionName, string chunkName, TypeMetadata typeMetadata, MethodMetadata methodMetadata, CodeBuilder builder, SymbolReferences references)
     {
     {
-        builder.AppendLine($"static readonly global::Lua.LuaFunction {functionName} = new global::Lua.LuaFunction({(methodMetadata.IsAsync ? "async" : "")} (context, buffer, ct) =>");
+        builder.AppendLine($@"static readonly global::Lua.LuaFunction {functionName} = new global::Lua.LuaFunction(""{chunkName}"", {(methodMetadata.IsAsync ? "async" : "")} (context, buffer, ct) =>");
 
 
         using (builder.BeginBlockScope())
         using (builder.BeginBlockScope())
         {
         {