From e384d7e4904ec8b768e911a19f8027341b4b43b8 Mon Sep 17 00:00:00 2001 From: routersys Date: Wed, 1 Jul 2026 17:36:16 +0900 Subject: [PATCH] =?UTF-8?q?obj.setanchor=E3=82=92=E5=AE=9F=E8=A3=85?= =?UTF-8?q?=E3=81=97Lua=E5=A4=89=E6=95=B0=E3=81=B8=E5=BA=A7=E6=A8=99?= =?UTF-8?q?=E3=82=92=E6=A0=BC=E7=B4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LuaScript/LuaScriptEngine.cs | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/LuaScript/LuaScriptEngine.cs b/LuaScript/LuaScriptEngine.cs index 2e1f846..8332850 100644 --- a/LuaScript/LuaScriptEngine.cs +++ b/LuaScript/LuaScriptEngine.cs @@ -1,3 +1,4 @@ +using LuaScript.Anchor; using LuaScript.Compat; using MoonSharp.Interpreter; using MoonSharp.Interpreter.Debugging; @@ -648,6 +649,42 @@ namespace LuaScript return value.Type == DataType.Number ? value : DynValue.NewNumber(0d); }); + obj["setanchor"] = DynValue.NewCallback((_, args) => + { + _activeCancellation.ThrowIfCancellationRequested(); + if (_activeContext is null || _script is null || args.Count < 2 || args[0].Type != DataType.String) + return DynValue.NewNumber(0d); + + var anchorName = args[0].String; + int count = AnchorSupport.ClampCount((int)(args[1].CastToNumber() ?? 0d)); + if (string.Equals(anchorName, AnchorSupport.TrackGroup, StringComparison.Ordinal)) + return DynValue.NewNumber(0d); + + var connection = AnchorConnection.None; + bool is3D = false; + for (int i = 2; i < args.Count; i++) + { + if (args[i].Type == DataType.String) + AnchorSupport.ApplyOption(args[i].String, ref connection, ref is3D); + } + + int stride = is3D ? 3 : 2; + var table = new Table(_script); + var source = _activeContext.AnchorSource; + for (int i = 0; i < count; i++) + { + AnchorSupport.ResolvePosition(source, anchorName, i, out double x, out double y, out double z); + table.Set(i * stride + 1, DynValue.NewNumber(x)); + table.Set(i * stride + 2, DynValue.NewNumber(y)); + if (is3D) + table.Set(i * stride + 3, DynValue.NewNumber(z)); + } + _script.Globals.Set(anchorName, DynValue.NewTable(table)); + + _activeContext.AddAnchorRequest(new AnchorRequestData(anchorName, count, connection, is3D)); + return DynValue.NewNumber(count); + }); + obj["setoption"] = DynValue.NewCallback((_, args) => { _activeCancellation.ThrowIfCancellationRequested();