当设置变量值时如果找不到变量则优先在临时变量上下文中声明变量

This commit is contained in:
zengwenjie
2025-10-16 12:24:25 +08:00
parent 7d18b88172
commit 413985e08f

View File

@@ -151,6 +151,7 @@ namespace Deedy.Testing
/// <param name="script">要执行的脚本</param>
public void Init(string script)
{
//TODO这里需要进行语法校验
this.Script.Clear();
string[] cmdLines = script.Split(['\r', '\n'], StringSplitOptions.RemoveEmptyEntries);
@@ -583,7 +584,6 @@ namespace Deedy.Testing
if (func.Name == funcName)
{
this.Invoke_FuncStack.Push(new Def_FuncInvoke(this.Control_CurrentLine + 1));
//TODO根据「Func」指令定义声明局部变量
string[] funcArgs = this.Script[func.Line].Split(' ', options: StringSplitOptions.RemoveEmptyEntries)[2..];
Array.Reverse(funcArgs);
for (int i = 0; i < funcArgs.Length; i++)
@@ -1084,7 +1084,10 @@ namespace Deedy.Testing
return;
}
}
this.Param_Global.Add(paramName, paramValue);
// 如果找不到已经定义好的参数,优先在局部变量表中声明参数
Dictionary<string, object> paramsContext = this.Param_Global;
if (this.Invoke_FuncStack.TryPeek(out var funcSpace)) paramsContext = funcSpace.LocalParams;
paramsContext.Add(paramName, paramValue);
}
/// <summary>
/// 从参数表中获取参数