Exemplo n.º 1
0
            public virtual dynamic Apply(RubyEvaluator e, dynamic self, params dynamic[] args)
            {
                var     originalContext        = e.env;
                var     originalReturningState = e.isReturning;
                dynamic result = null;

                try
                {
                    e.env         = capture.AddBinding("this", self);
                    e.isReturning = false;
                    int i = 0;
                    foreach (var p in parms.Nodes)
                    {
                        e.AddBinding(p.Text, args[i++]);
                    }
                    e.Eval(body);
                    result = e.result;
                }
                finally
                {
                    e.result      = null;
                    e.env         = originalContext;
                    e.isReturning = originalReturningState;
                }
                return(result);
            }
Exemplo n.º 2
0
 public static void Test(string s, dynamic expected = null)
 {
     try
     {
         if (expected != null)
         {
             Console.WriteLine("Testing: {0}", s);
             Console.WriteLine("Expecting {0}", expected);
             dynamic result = RubyEvaluator.RunScript(s);
             Console.WriteLine("Result {0}", result);
             if (result != expected)
             {
                 Console.WriteLine("ERROR!");
             }
         }
         else
         {
             Console.WriteLine("Testing: {0}", s);
             RubyEvaluator.RunScript(s);
         }
     }
     catch (Exception e)
     {
         Console.WriteLine("Error occured: " + e.Message);
     }
 }
Exemplo n.º 3
0
        public object ExecuteText(string text)
        {
            //Parser parser = new Parser(text);
            //object result = null;

            //for (var command = parser.ParseCommand(); command != null; command = parser.ParseCommand())
            //    result = command.Evaluate(this.rootcontext);

            //return result;
            return(RubyEvaluator.RunScript(text));
        }
Exemplo n.º 4
0
 public override dynamic Apply(RubyEvaluator e, dynamic self, params dynamic[] args)
 {
     return(func(self, args));
 }