已经完成条件指令的调试
This commit is contained in:
@@ -21,9 +21,14 @@ Func Add var1x var2x
|
||||
math AddResult @var1x 777 + @var2 - @var2x -
|
||||
retu AddResult
|
||||
EndF
|
||||
|
||||
//调用自定义方法
|
||||
Call Add @var1 99
|
||||
PopV result
|
||||
ifth true 4 3 <
|
||||
letp result 248
|
||||
else
|
||||
letp result 80
|
||||
endi
|
||||
";
|
||||
Todo todo = new Todo();
|
||||
todo.Init(script);
|
||||
|
||||
@@ -158,7 +158,7 @@ namespace Deedy.Testing
|
||||
for (int lineNum = 0; lineNum < cmdLines.Length; lineNum++)
|
||||
{
|
||||
string command = cmdLines[lineNum].Trim();
|
||||
if (!string.IsNullOrEmpty(command)) this.Script.Add(command);
|
||||
if (!string.IsNullOrEmpty(command) && !command.StartsWith('/')) this.Script.Add(command);
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
@@ -231,6 +231,7 @@ namespace Deedy.Testing
|
||||
case "endi": this.CmdC_EndI(); break;
|
||||
case "endw": this.CmdC_EndW(); break;
|
||||
case "reen": this.CmdC_Reen(); break;
|
||||
case "else": this.CmdC_Else(); break;
|
||||
|
||||
case "func": this.CmdI_Func(cmdArgs); break;
|
||||
case "call": this.CmdI_Call(cmdArgs); break;
|
||||
@@ -246,7 +247,7 @@ namespace Deedy.Testing
|
||||
case "push": this.CmdS_Push(cmdArgs); break;
|
||||
case "popv": this.CmdS_PopV(cmdArgs); break;
|
||||
|
||||
default: break;
|
||||
default: this.Control_CurrentLine++; break;
|
||||
}
|
||||
break;
|
||||
case Mode.Reentry: // 重启脚本逻辑
|
||||
@@ -410,6 +411,19 @@ namespace Deedy.Testing
|
||||
//HACK:如果需要支持代码块级局部变量则需要在此处闭合代码块
|
||||
}
|
||||
/// <summary>
|
||||
/// 条件执行的「Else」逻辑
|
||||
/// </summary>
|
||||
protected void CmdC_Else()
|
||||
{
|
||||
this.Control_CurrentLine++;
|
||||
while (this.Control_CurrentLine < this.Script.Count)
|
||||
{
|
||||
string cmd = Pre_Hand(this.Script[this.Control_CurrentLine]);
|
||||
if (cmd == "endI") break;
|
||||
else this.Control_CurrentLine++;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// $>> 跳转到指定的指令序列位置
|
||||
/// <para>注意:跳转指令不会超出「Funcation」范围;如果超出,引擎会自动修正</para>
|
||||
/// </summary>
|
||||
@@ -475,7 +489,11 @@ namespace Deedy.Testing
|
||||
if (!funcHandle.LocalParams.TryAdd(paramDefine[0].TrimStart('@'), paramValue))
|
||||
funcHandle.LocalParams[paramDefine[0].TrimStart('@')] = paramValue;
|
||||
}
|
||||
else this.CmdI_VarP(cmdArgs ?? "");
|
||||
else
|
||||
{
|
||||
this.CmdI_VarP(cmdArgs ?? "");
|
||||
return; // 由于「CmdI_VarP」方法已经变更脚本指令“游标”,所以此处直接返回
|
||||
}
|
||||
}
|
||||
this.Control_CurrentLine++;
|
||||
}
|
||||
@@ -881,16 +899,17 @@ namespace Deedy.Testing
|
||||
/// <returns>表达式的真值,如果表达式有误则返回指定的值</returns>
|
||||
private bool CmdP_Cond(string condition)
|
||||
{
|
||||
bool result = true;
|
||||
bool result = false;
|
||||
Stack<object> stack = [];
|
||||
string[] conParts = condition.Split(' ', options: StringSplitOptions.RemoveEmptyEntries);
|
||||
if (conParts.Length > 0)
|
||||
{
|
||||
result = bool.Parse(conParts[0].ToLower());
|
||||
int index = 0;
|
||||
_ = bool.TryParse(conParts[0], out result);
|
||||
if (conParts.Length == 1) return result;
|
||||
|
||||
int index = 1;
|
||||
while (index < conParts.Length)
|
||||
{
|
||||
index++;
|
||||
{
|
||||
switch (conParts[index])
|
||||
{
|
||||
case "!": this.Cond_Nega(stack); break;
|
||||
@@ -908,6 +927,7 @@ namespace Deedy.Testing
|
||||
|
||||
default: stack.Push(conParts[index]); break;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
}
|
||||
if (stack.Count > 0) result = this.Val_Boolean(stack.Pop());
|
||||
@@ -1056,8 +1076,8 @@ namespace Deedy.Testing
|
||||
/// 设置参数表中的一个参数
|
||||
/// <para>备注:先去局部变量中查找,再去全局变量中查找,最后去外部引用变量中查找</para>
|
||||
/// </summary>
|
||||
/// <param name="paramName"></param>
|
||||
/// <param name="paramValue"></param>
|
||||
/// <param name="paramName">变量名称</param>
|
||||
/// <param name="paramValue">变量的值,支持引用</param>
|
||||
private void ParamSetter(string paramName, object paramValue)
|
||||
{
|
||||
//HACK:暂时不支持代码块级的局部变量
|
||||
@@ -1093,9 +1113,9 @@ namespace Deedy.Testing
|
||||
/// 从参数表中获取参数
|
||||
/// <para>备注:先去局部变量中查找,再去全局变量中查找,最后去外部引用变量中查找</para>
|
||||
/// </summary>
|
||||
/// <param name="paramName"></param>
|
||||
/// <param name="default"></param>
|
||||
/// <returns></returns>
|
||||
/// <param name="paramName">变量名称</param>
|
||||
/// <param name="default">默认值</param>
|
||||
/// <returns>如果找不到变量则返回默认值</returns>
|
||||
private object ParamGetter(string paramName, object @default)
|
||||
{
|
||||
//HACK:暂时不支持代码块级的局部变量
|
||||
|
||||
Reference in New Issue
Block a user