脚本节点能够自定义变量名

This commit is contained in:
fengjiayi
2025-03-14 21:38:07 +08:00
parent ef11edf7f1
commit 1e09675ef1
9 changed files with 188 additions and 29 deletions

View File

@@ -8,12 +8,19 @@ namespace Serein.Script.Node
{
/// <summary>
/// 变量节点
/// 赋值节点
/// </summary>
public class AssignmentNode : ASTNode
{
/// <summary>
/// 变量名称
/// </summary>
public string Variable { get; }
/// <summary>
/// 对应的节点
/// </summary>
public ASTNode Value { get; }
public AssignmentNode(string variable, ASTNode value) => (Variable, Value) = (variable, value);
}

View File

@@ -212,6 +212,8 @@ namespace Serein.Script
/// <returns></returns>
private async Task<object?> ExecutionProgramNodeAsync(IScriptInvokeContext context, ProgramNode programNode)
{
// 加载变量
// 遍历 ProgramNode 中的所有语句并执行它们
foreach (var statement in programNode.Statements)
{
@@ -366,8 +368,6 @@ namespace Serein.Script
}
public async Task<object?> InterpretAsync(IScriptInvokeContext context, ASTNode node)
{
if(node == null)