From 4528748493d2e3808490fc6e3c2c863bcbcaefc3 Mon Sep 17 00:00:00 2001 From: routersys Date: Sat, 27 Jun 2026 09:33:13 +0900 Subject: [PATCH] =?UTF-8?q?=E3=83=86=E3=82=B9=E3=83=88=E7=94=A8LuaJIT?= =?UTF-8?q?=E3=83=AC=E3=83=BC=E3=83=B3(=E5=88=A5=E3=83=97=E3=83=AD?= =?UTF-8?q?=E3=82=BB=E3=82=B9=E9=A7=86=E5=8B=95)=E3=83=98=E3=83=AB?= =?UTF-8?q?=E3=83=91=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.Tests/LuaJitLane.cs | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 LuaScript.Tests/LuaJitLane.cs diff --git a/LuaScript.Tests/LuaJitLane.cs b/LuaScript.Tests/LuaJitLane.cs new file mode 100644 index 0000000..32556eb --- /dev/null +++ b/LuaScript.Tests/LuaJitLane.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; + +namespace LuaScript.Tests +{ + internal sealed class LuaJitLane + { + private readonly string _nativeDir = Path.Combine(AppContext.BaseDirectory, "native"); + + public bool Available => File.Exists(Path.Combine(_nativeDir, "luajit.exe")); + + public string[] Eval(IReadOnlyList expressions) + { + string vectors = Path.GetTempFileName(); + File.WriteAllLines(vectors, expressions); + try + { + var psi = new ProcessStartInfo + { + FileName = Path.Combine(_nativeDir, "luajit.exe"), + WorkingDirectory = _nativeDir, + RedirectStandardOutput = true, + RedirectStandardError = true, + UseShellExecute = false, + }; + psi.ArgumentList.Add("runner.lua"); + psi.ArgumentList.Add(Path.Combine(_nativeDir, "shim.lua")); + psi.ArgumentList.Add(vectors); + + using var process = Process.Start(psi) + ?? throw new InvalidOperationException("Failed to start luajit.exe"); + string stdout = process.StandardOutput.ReadToEnd(); + string stderr = process.StandardError.ReadToEnd(); + process.WaitForExit(); + if (process.ExitCode != 0) + throw new InvalidOperationException("luajit exited " + process.ExitCode + ": " + stderr); + + return stdout.Replace("\r\n", "\n").Split('\n'); + } + finally + { + File.Delete(vectors); + } + } + } +}