From 06e2afa7ed223c17255ce63526a6b3bf08f90e0d Mon Sep 17 00:00:00 2001 From: routersys Date: Tue, 30 Jun 2026 07:56:48 +0900 Subject: [PATCH] =?UTF-8?q?=E3=82=B9=E3=82=AF=E3=83=AA=E3=83=97=E3=83=88?= =?UTF-8?q?=E5=A4=89=E6=8F=9B=E3=81=AB=E8=A1=8C=E7=95=AA=E5=8F=B7=E3=83=9E?= =?UTF-8?q?=E3=83=83=E3=83=94=E3=83=B3=E3=82=B0=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LuaScript/Compat/AviUtlScript.cs | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/LuaScript/Compat/AviUtlScript.cs b/LuaScript/Compat/AviUtlScript.cs index 681a66a..623ec38 100644 --- a/LuaScript/Compat/AviUtlScript.cs +++ b/LuaScript/Compat/AviUtlScript.cs @@ -13,10 +13,12 @@ namespace LuaScript.Compat Param, } - public static string Transform(string source) + public static string Transform(string source) => TransformWithMap(source).Code; + + public static (string Code, int[] LineMap) TransformWithMap(string source) { if (string.IsNullOrEmpty(source)) - return source; + return (source, []); var lines = source.Replace("\r\n", "\n").Replace("\r", "\n").Split('\n'); @@ -48,15 +50,24 @@ namespace LuaScript.Compat AppendDeclarations(lines[i], prelude); if (!hasSection && prelude.Count == 0) - return source; + return (source, []); var builder = new StringBuilder(source.Length + 64); - foreach (var declaration in prelude) - builder.Append(declaration).Append('\n'); - for (int i = sectionStart; i < sectionEnd; i++) - builder.Append(lines[i]).Append('\n'); + var lineMap = new int[prelude.Count + (sectionEnd - sectionStart)]; + int row = 0; - return builder.ToString(); + foreach (var declaration in prelude) + { + builder.Append(declaration).Append('\n'); + lineMap[row++] = -1; + } + for (int i = sectionStart; i < sectionEnd; i++) + { + builder.Append(lines[i]).Append('\n'); + lineMap[row++] = i; + } + + return (builder.ToString(), lineMap); } private static void AppendDeclarations(string line, List prelude)