void ProcessCallForeach() { CodeForeach code = (CodeForeach)m_scriptInstruction.Operand0; ScriptObject loop = ResolveOperand(code.LoopObject); if (!(loop is ScriptFunction)) { throw new ExecutionException(m_script, "foreach函数必须返回一个ScriptFunction"); } object obj; ScriptFunction func = (ScriptFunction)loop; ScriptContext context; for ( ; ;) { obj = func.Call(); if (obj == null) { return; } context = new ScriptContext(m_script, code.BlockExecutable, this, Executable_Block.Foreach); context.Initialize(code.Identifier, m_script.CreateObject(obj)); context.Execute(); if (context.IsOver) { break; } } }
private void ProcessCallForeach() { object obj3; CodeForeach @foreach = (CodeForeach)this.m_scriptInstruction.operand0; ScriptObject obj2 = this.ResolveOperand(@foreach.LoopObject); if (!(obj2 is ScriptFunction)) { throw new ExecutionException(this.m_script, "foreach函数必须返回一个ScriptFunction"); } ScriptFunction function = (ScriptFunction)obj2; Label_003E: obj3 = function.Call(); if (obj3 != null) { ScriptContext context = new ScriptContext(this.m_script, @foreach.BlockExecutable, this, Executable_Block.Foreach); context.Initialize(@foreach.Identifier, this.m_script.CreateObject(obj3)); context.Execute(); if (!context.IsOver) { goto Label_003E; } } }
int SortComparison(object lhs, object rhs) { object result = comparator.Call(interpreter, token, new List <object>() { lhs, rhs }); if (!(result is double)) { throw new ErrorHandler.RuntimeError(token, "Unexpected result type from comparator function (expected number)"); } return(Convert.ToInt32(result)); }
private object CallFunction(string func) { try { ScriptFunction fun = Table.GetValue(func) as ScriptFunction; if (fun != null) { return(fun.Call()); } } catch (System.Exception ex) { Debug.LogError("Stack : " + Launch.Script.GetStackInfo()); Debug.LogError("CallFunction " + func + " is error " + ex.ToString()); } return(null); }
public object Call(Interpreter interpreter, Token token, List <object> arguments) { ScriptFunction callback = (ScriptFunction)arguments[0]; if (callback.Arity() != 1) { throw new ErrorHandler.RuntimeError(token, "Callback has an incorrect number of parameters (expected 1, found " + callback.Arity() + ")"); } foreach (object element in self.container) { callback.Call(interpreter, token, new List <object>() { element }); } return(null); }
public object Call(Interpreter interpreter, Token token, List arguments) { ScriptFunction callback = (ScriptFunction)arguments[0]; if (callback.Arity() != 2) { throw new ErrorHandler.RuntimeError(token, "Callback has an incorrect number of parameters (expected 2, found " + callback.Arity() + ")"); } foreach (Pair kvp in self.container) { callback.Call(interpreter, token, new List() { kvp.Key, kvp.Value }); } return(null); }
public object Call(Interpreter interpreter, Token token, List <object> arguments) { ScriptFunction callback = (ScriptFunction)arguments[0]; List <object> resultsContainer = new List <object>(); if (callback.Arity() != 1) { throw new ErrorHandler.RuntimeError(token, "Callback has an incorrect number of parameters (expected 1, found " + callback.Arity() + ")"); } foreach (object element in self.container) { object result = callback.Call(interpreter, token, new List <object>() { element }); if (interpreter.CheckIsTruthy(result)) { resultsContainer.Add(element); } } return(new ArrayInstance(resultsContainer)); }
public object Call(Interpreter interpreter, Token token, List arguments) { ScriptFunction callback = (ScriptFunction)arguments[0]; Dict resultsContainer = new Dict(); if (callback.Arity() != 2) { throw new ErrorHandler.RuntimeError(token, "Callback has an incorrect number of parameters (expected 2, found " + callback.Arity() + ")"); } foreach (Pair kvp in self.container) { object result = callback.Call(interpreter, token, new List() { kvp.Key, kvp.Value }); if (interpreter.CheckIsTruthy(result)) { resultsContainer[kvp.Key] = kvp.Value; } } return(new DictionaryInstance(resultsContainer)); }