重写了节点主动中断功能,修改了运行环境持久化注册已有实例的逻辑。

This commit is contained in:
fengjiayi
2024-12-26 22:24:44 +08:00
parent 7a6f8c407b
commit 3a7a8483e8
24 changed files with 428 additions and 563 deletions

View File

@@ -26,6 +26,7 @@ namespace Serein.Script
/// </summary>
public interface IScriptInvokeContext
{
IDynamicContext FlowContext { get; }
/// <summary>
/// 是否该退出了
/// </summary>
@@ -61,6 +62,13 @@ namespace Serein.Script
public class ScriptInvokeContext : IScriptInvokeContext
{
public ScriptInvokeContext(IDynamicContext dynamicContext)
{
FlowContext = dynamicContext;
}
public IDynamicContext FlowContext{ get; }
/// <summary>
/// 定义的变量
/// </summary>
@@ -76,6 +84,7 @@ namespace Serein.Script
/// </summary>
public bool IsCheckNullValue { get; set; }
object IScriptInvokeContext.GetVarValue(string varName)
{
_variables.TryGetValue(varName, out var value);
@@ -309,6 +318,11 @@ namespace Serein.Script
}
private async Task<object> InterpretFunctionCallAsync(IScriptInvokeContext context, FunctionCallNode functionCallNode)
{
if (functionCallNode.FunctionName.Equals("GetFlowContext", StringComparison.OrdinalIgnoreCase))
{
return context.FlowContext;
}
// 评估函数参数
var arguments = new object?[functionCallNode.Arguments.Count];
for (int i = 0; i < functionCallNode.Arguments.Count; i++)
@@ -321,6 +335,7 @@ namespace Serein.Script
object? instance = null; // 静态方法不需要传入实例所以可以传入null
// 查找并执行对应的函数
if (_functionTable.TryGetValue(funcName, out DelegateDetails? function))
{