From 3c0e13c85d5c541b9ed1a328a195303fd5e2839d 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=A8MoonSharp?= =?UTF-8?q?=E3=83=AC=E3=83=BC=E3=83=B3=E3=83=98=E3=83=AB=E3=83=91=E3=82=92?= =?UTF-8?q?=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LuaScript.Tests/MoonSharpLane.cs | 46 ++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 LuaScript.Tests/MoonSharpLane.cs diff --git a/LuaScript.Tests/MoonSharpLane.cs b/LuaScript.Tests/MoonSharpLane.cs new file mode 100644 index 0000000..2d02b14 --- /dev/null +++ b/LuaScript.Tests/MoonSharpLane.cs @@ -0,0 +1,46 @@ +using LuaScript; +using MoonSharp.Interpreter; + +namespace LuaScript.Tests +{ + internal sealed class MoonSharpLane + { + private readonly Script _script; + + public MoonSharpLane() + { + _script = new Script( + CoreModules.Basic | + CoreModules.Math | + CoreModules.String | + CoreModules.Table | + CoreModules.Bit32 | + CoreModules.TableIterators | + CoreModules.Metatables | + CoreModules.ErrorHandling); + + var anim = new Table(_script); + AnimTableRegistrar.RegisterFunctions(anim); + _script.Globals["anim"] = anim; + } + + public DynValue Run(string code) => _script.DoString(code); + + public double Number(string expression) => Run("return " + expression).Number; + + public bool Boolean(string expression) => Run("return " + expression).Boolean; + + public string? Text(string expression) => Run("return " + expression).CastToString(); + + public DataType Type(string expression) => Run("return " + expression).Type; + + public double[] Tuple(string expression, int count) + { + var table = Run("return {" + expression + "}").Table; + var result = new double[count]; + for (int i = 0; i < count; i++) + result[i] = table.Get(i + 1).Number; + return result; + } + } +}