protected override RunControlType ExecuteInternal(ScriptExecutionEnvironment env, out ScriptVariable returnValue) { returnValue = null; if (!this.Do) { ScriptVariable condition = this.Condition.Calculate(env); if (condition == null || !condition.ToBoolean()) { return(RunControlType.None); } } while (true) { RunControlType ctrl = this.Statement.Execute(env, out returnValue); if (ctrl == RunControlType.Break) { return(RunControlType.None); } if (ctrl == RunControlType.Return) { return(RunControlType.Return); } ScriptVariable condition = this.Condition.Calculate(env); if (condition == null || !condition.ToBoolean()) { return(RunControlType.None); } } }
public override bool FromScriptVariable(TEnvironment environment, ScriptVariable variable, ref string errorMessage) { switch (variable.Type) { case ScriptVariableType.Boolean: this.Value = variable.ToBoolean(); return(true); default: errorMessage = MotionDataHandler.Properties.Settings.Default.Msg_SpecifyBoolean; return(false); } }
public ScriptVariable Call(IList <ScriptVariable> args, ScriptConsole console) { ScriptVariable arg = null; if (args.Count >= 1) { arg = args[0]; } if (arg == null) { return(null); } return(new BooleanVariable(arg.ToBoolean())); }
protected override ScriptVariable CalculateInternal(ScriptExecutionEnvironment env) { ScriptVariable operand = this.Operand.Calculate(env); switch (this.Operator) { case OperatorType.Minus: return(new NumberVariable(-operand.ToNumber())); case OperatorType.Plus: return(new NumberVariable(operand.ToNumber())); case OperatorType.Not: return(new BooleanVariable(!operand.ToBoolean())); } throw new NotImplementedException(this.Operator.ToString()); }
protected override ScriptVariable CalculateInternal(ScriptExecutionEnvironment env) { switch (this.Operator) { case OperatorType.Condition: ScriptVariable p1 = this.First.Calculate(env); if (p1 != null && p1.ToBoolean()) { return(this.Second.Calculate(env)); } else { return(this.Third.Calculate(env)); } default: throw new NotImplementedException(this.Operator.ToString()); } }
protected override RunControlType ExecuteInternal(ScriptExecutionEnvironment env, out ScriptVariable returnValue) { returnValue = null; env.Variables.EnterScope(); try { if (this.Initialize != null) { this.Initialize.Calculate(env); } while (true) { if (this.Condition != null) { ScriptVariable condition = this.Condition.Calculate(env); if (condition == null || !condition.ToBoolean()) { return(RunControlType.None); } } if (this.Statement != null) { RunControlType ctrl = this.Statement.Execute(env, out returnValue); if (ctrl == RunControlType.Break) { return(RunControlType.None); } if (ctrl == RunControlType.Return) { return(RunControlType.Return); } } if (this.Continue != null) { this.Continue.Calculate(env); } } } finally { env.Variables.ExitScope(); } }
protected override RunControlType ExecuteInternal(ScriptExecutionEnvironment env, out ScriptVariable returnValue) { returnValue = null; ScriptVariable condition = this.Condition.Calculate(env); if (condition != null && condition.ToBoolean()) { if (this.Then == null) { return(RunControlType.None); } RunControlType ctrl = this.Then.Execute(env, out returnValue); return(ctrl); } else { if (this.Else == null) { return(RunControlType.None); } RunControlType ctrl = this.Else.Execute(env, out returnValue); return(ctrl); } }
protected override ScriptVariable CalculateInternal(ScriptExecutionEnvironment env) { ScriptVariable left = this.Left.Calculate(env); // ショートサーキット演算子 switch (this.Operator) { case OperatorType.And: if (left == null) { return(null); } if (!left.ToBoolean()) { return(new BooleanVariable(false)); } return(this.Right.Calculate(env)); case OperatorType.Or: if (left == null) { return(null); } if (left.ToBoolean()) { return(new BooleanVariable(true)); } return(this.Right.Calculate(env)); } // 右辺 ScriptVariable right = this.Right.Calculate(env); if (left == null || right == null) { // 片方nullの場合は等価比較演算以外はnull switch (this.Operator) { case OperatorType.Eq: return(new BooleanVariable(left == right)); case OperatorType.Ne: return(new BooleanVariable(left != right)); default: return(null); } } // 普通の二項演算 switch (this.Operator) { case OperatorType.Cross: return(left.Multiply(right)); case OperatorType.Plus: return(left.Add(right)); case OperatorType.Minus: return(left.Subtract(right)); case OperatorType.Slash: return(left.Divide(right)); case OperatorType.Percent: return(left.Remainder(right)); } // 比較演算子 int?tmp = left.CompareTo(right); if (tmp.HasValue) { int value = tmp.Value; switch (this.Operator) { case OperatorType.Eq: return(new BooleanVariable(value == 0)); case OperatorType.Ne: return(new BooleanVariable(value != 0)); case OperatorType.Gt: return(new BooleanVariable(value > 0)); case OperatorType.Ge: return(new BooleanVariable(value >= 0)); case OperatorType.Lt: return(new BooleanVariable(value < 0)); case OperatorType.Le: return(new BooleanVariable(value <= 0)); } } return(null); }