Example #1
0
        public virtual RBasic BasicSend(string name, RBasic[] args, RCBlock block)
        {
            RMetaObject origin;
            RCMethod    m = (RCMethod)klass.SearchMethod(name, out origin);

            /*
             * Console.WriteLine("sending");
             * Console.WriteLine("self " + this.ToString());
             * Console.WriteLine("send " + name + " found " + m.ToString());
             * foreach(RBasic ro in args) {
             *  Console.WriteLine("arg " + ro.ToString());
             * }
             */
            if (m == null)
            {
                Console.WriteLine("Available methods:");

                foreach (object o in klass.ClassInstanceMethods(new object[] { ruby.oTrue }))
                {
                    Console.WriteLine(o.ToString());
                }

                throw new Exception("Method not found: " + name);
            }
            return(m.Call(ruby.GetCurrentContext(), this, args, block));
        }
Example #2
0
            public override RBasic Call(RThread th, RBasic self, RBasic[] args, RCBlock block)
            {
                th.PushLegacyBlock(block);
                RBasic ret = RClass.ConvertToRuby(ruby, method(self, (object[])args));

                th.PopLegacyBlock();
                return(ret);
            }
Example #3
0
            public override RBasic Call(RThread th, RBasic self, RBasic[] args, RCBlock block)
            {
                th.PushLegacyBlock(block);

                /*
                 * Console.WriteLine("Invoke " + method_info.Name + " self=" + self.GetType().Name + ":" + self.ToString());
                 * Console.WriteLine("mi_type=" + method_info.DeclaringType.Name);
                 * foreach(ParameterInfo p in method_info.GetParameters()) {
                 *  Console.WriteLine("mparam: " + p.ParameterType.Name);
                 * }
                 * foreach(RBasic r in args) {
                 *  Console.WriteLine("realparam: " + r.GetType().Name);
                 * }
                 */

                // return (RBasic)method_info.Invoke(null, new object[] { self, args });
                ParameterInfo[] pi = method_info.GetParameters();
                RBasic          ret;

                if (pi.Length > 0 && pi[0].ParameterType == typeof(object[]))
                {
                    ret = RClass.ConvertToRuby(ruby, method_info.Invoke(self, new object[] { args }));
                }
                else
                {
                    object[] ca = new object[pi.Length];
                    for (int i = 0; i < pi.Length; i++)
                    {
                        if (pi[i].ParameterType == typeof(int))
                        {
                            ca[i] = args[i].ToInteger();
                        }
                        else
                        {
                            ca[i] = args[i];
                        }
                    }

                    ret = RClass.ConvertToRuby(ruby, method_info.Invoke(self, ca));
                }
                th.PopLegacyBlock();
                return(ret);
            }
Example #4
0
 // A block argument to blocks is allowed in newer versions of Ruby
 public abstract RBasic Call(RThread thread, RBasic[] args, RCBlock block);
Example #5
0
 public void PushLegacyBlock(RCBlock b)
 {
     //Console.WriteLine("Push block " + b);
     legacy_blocks.Push(b);
 }
Example #6
0
 public virtual RBasic BasicSend(string name, RBasic[] args, RCBlock block)
 {
     RMetaObject origin;
     RCMethod m = (RCMethod)klass.SearchMethod(name, out origin);
     /*
     Console.WriteLine("sending");
     Console.WriteLine("self " + this.ToString());
     Console.WriteLine("send " + name + " found " + m.ToString());
     foreach(RBasic ro in args) {
         Console.WriteLine("arg " + ro.ToString());
     }
     */
     if(m == null) {
         Console.WriteLine("Available methods:");
         
         foreach(object o in klass.ClassInstanceMethods(new object[] {ruby.oTrue})) {
             Console.WriteLine(o.ToString());
         }
         
         throw new Exception("Method not found: " + name);
     }
     return m.Call(ruby.GetCurrentContext(), this, args, block);
 }
Example #7
0
            public override RBasic Call(RThread th, RBasic self, RBasic[] args, RCBlock block)
            {
                th.PushLegacyBlock(block);
                /*
                Console.WriteLine("Invoke " + method_info.Name + " self=" + self.GetType().Name + ":" + self.ToString());
                Console.WriteLine("mi_type=" + method_info.DeclaringType.Name);
                foreach(ParameterInfo p in method_info.GetParameters()) {
                    Console.WriteLine("mparam: " + p.ParameterType.Name);
                }
                foreach(RBasic r in args) {
                    Console.WriteLine("realparam: " + r.GetType().Name);
                }
                */

                // return (RBasic)method_info.Invoke(null, new object[] { self, args });
                ParameterInfo[] pi = method_info.GetParameters();
                RBasic ret;
                
                if(pi.Length > 0 && pi[0].ParameterType == typeof(object[])) {                        
                    ret = RClass.ConvertToRuby(ruby, method_info.Invoke(self, new object[] { args }));
                } else {
                    object[] ca = new object[pi.Length];
                    for(int i = 0; i < pi.Length; i++) {
                        if(pi[i].ParameterType == typeof(int)) {
                            ca[i] = args[i].ToInteger();
                        } else {
                            ca[i] = args[i];
                        }
                    }
                
                    ret = RClass.ConvertToRuby(ruby, method_info.Invoke(self, ca));
                }
                th.PopLegacyBlock();
                return ret;
            }
Example #8
0
 public override RBasic Call(RThread th, RBasic self, RBasic[] args, RCBlock block)
 {
     th.PushLegacyBlock(block);
     RBasic ret = RClass.ConvertToRuby(ruby, method(self, (object[])args));
     th.PopLegacyBlock();
     return ret;
 }
Example #9
0
 public void PushLegacyBlock(RCBlock b)
 {
     //Console.WriteLine("Push block " + b);
     legacy_blocks.Push(b);
 }
Example #10
0
 // A block argument to blocks is allowed in newer versions of Ruby
 public abstract RBasic Call(RThread thread, RBasic[] args, RCBlock block);