Esempio n. 1
0
        public virtual Value execute(Value[] parameters = null, Value caller = null)
        {
            if (nativeCallback != null)
            {
                return(nativeCallback(caller, parameters));
            }
            // we need to store all references in a temporary xfq (execution funqtion) so that the original funqtion is not mutated
            Log.spam("executing function:\n" + this.ToString());
            Funqtion xfq = new Funqtion(parent);

            if (parameters != null)
            {
                for (int i = 0; i < parameters.Length; i++)
                {
                    if (i >= this.parameters.Count)
                    {
                        throw new Exception("more parameters provided than funqtion accepts");
                    }
                    Log.spam(this.parameters[i] + " = " + parameters[i].str());
                    xfq.set(this.parameters[i], new Reference(parameters[i]));
                }
            }
            foreach (Segment s in segments)
            {
                Value r = s.execute(xfq);
                if (s.returning && r != null)
                {
                    Log.spam("reached return statement, returning " + r.str());
                    return(r);
                }
            }
            return(null);
        }