Пример #1
0
            private void ObjectMonkeyPatch(RubyModule /*!*/ module)
            {
                Debug.Assert(module == Context.ObjectClass);

                DefineLibraryMethod(module, "object_monkey", 0x9, new[] {
                    LibraryOverload.Reflect(new Func <object, string>(MonkeyWorker)),
                });
            }
Пример #2
0
 public static void DefineLibraryMethod(RubyModule /*!*/ module, string /*!*/ name, int attributes,
                                        uint overloadAttributes1, Delegate /*!*/ overload1)
 {
     if (!SkipDefinition(module, attributes))
     {
         DefineLibraryMethod(module, name, attributes, new[] {
             LibraryOverload.Create(overload1, overloadAttributes1)
         });
     }
 }
Пример #3
0
 protected override void LoadModules()
 {
     DefineGlobalModule("Tests", typeof(DefaultProtocolTester), (int)ModuleRestrictions.NoUnderlyingType, null, (module) => {
         DefineLibraryMethod(module, "to_int_to_str", (int)RubyMethodAttributes.PublicSingleton, new[] {
             LibraryOverload.Reflect(new Func <RubyModule, Union <int, MutableString>, RubyArray>(ToIntToStr)),
         });
         DefineLibraryMethod(module, "to_str_to_int", (int)RubyMethodAttributes.PublicSingleton, new[] {
             LibraryOverload.Reflect(new Func <RubyModule, Union <MutableString, int>, RubyArray>(ToStrToInt)),
         });
     },
                        null, RubyModule.EmptyArray);
 }
Пример #4
0
 public static void DefineLibraryMethod(RubyModule /*!*/ module, string /*!*/ name, int attributes,
                                        uint[] /*!*/ overloadAttributes, params Delegate[] /*!*/ overloads)
 {
     if (!SkipDefinition(module, attributes))
     {
         var infos = new LibraryOverload[overloads.Length];
         for (int i = 0; i < overloads.Length; i++)
         {
             infos[i] = LibraryOverload.Create(overloads[i], overloadAttributes[i]);
         }
         DefineLibraryMethod(module, name, attributes, infos);
     }
 }
Пример #5
0
        public static object Included(RubyContext /*!*/ context, RubyModule /*!*/ self, RubyModule /*!*/ includedIn)
        {
            var singleton = includedIn.GetOrCreateSingletonClass();

            singleton.AddMethod(
                context,
                "induced_from",
                new RubyLibraryMethodInfo(
                    new[] { LibraryOverload.Create(new Func <RubyModule, object, object>(InducedFrom), false, 0, 0) },
                    RubyMethodVisibility.Public,
                    singleton
                    )
                );
            return(self);
        }
Пример #6
0
        private void initRuby()
        {
            ScriptRuntimeSetup runtimeSetup = ScriptRuntimeSetup.ReadConfiguration();
            var languageSetup = IronRuby.RubyHostingExtensions.AddRubySetup(runtimeSetup);

            runtimeSetup.DebugMode      = false;
            runtimeSetup.PrivateBinding = false;
            runtimeSetup.HostType       = typeof(RhoHost);

            languageSetup.Options["NoAdaptiveCompilation"] = false;
            languageSetup.Options["CompilationThreshold"]  = 0;
            languageSetup.Options["Verbosity"]             = 2;

            m_runtime = IronRuby.Ruby.CreateRuntime(runtimeSetup);
            Stream errStream = new CRhoOutputStream(true);

            m_runtime.IO.SetErrorOutput(errStream, new StreamWriter(errStream, System.Text.Encoding.UTF8));
            Stream outStream = new CRhoOutputStream(false);

            m_runtime.IO.SetOutput(outStream, new StreamWriter(outStream, System.Text.Encoding.UTF8));

            m_engine  = IronRuby.Ruby.GetEngine(m_runtime);
            m_context = (RubyContext)Microsoft.Scripting.Hosting.Providers.HostingHelpers.GetLanguageContext(m_engine);

            m_context.ObjectClass.SetConstant("RHO_WP7", 1);
            m_context.ObjectClass.AddMethod(m_context, "__rhoGetCallbackObject", new RubyLibraryMethodInfo(
                                                new[] { LibraryOverload.Create(new Func <System.Object, System.Int32, System.Object>(RhoKernelOps.__rhoGetCallbackObject), false, 0, 0) },
                                                RubyMethodVisibility.Public,
                                                m_context.ObjectClass
                                                ));
            m_context.ObjectClass.AddMethod(m_context, "__rho_exist_in_resources", new RubyLibraryMethodInfo(
                                                new[] { LibraryOverload.Create(new Func <System.Object, System.String, System.Object>(RhoKernelOps.__rho_exist_in_resources), false, 0, 0) },
                                                RubyMethodVisibility.Public,
                                                m_context.ObjectClass
                                                ));

            m_context.Loader.LoadAssembly("RhoRubyLib", "rho.rubyext.rubyextLibraryInitializer", true, true);

            System.Collections.ObjectModel.Collection <string> paths = new System.Collections.ObjectModel.Collection <string>();
            paths.Add("lib");
            paths.Add("apps/app");
            m_engine.SetSearchPaths(paths);
        }
Пример #7
0
        // add methods to the generated class
        private static void AddClassMembers(RubyClass /*!*/ cls, string[] /*!*/ structMembers)
        {
            var newInstance = new RuleGenerator(RuleGenerators.InstanceConstructor);
            var context     = cls.Context;

            var singletonClass = cls.GetOrCreateSingletonClass();

            singletonClass.AddMethod(context, "[]", new RubyCustomMethodInfo(newInstance, RubyMemberFlags.Public, singletonClass));
            singletonClass.AddMethod(context, "new", new RubyCustomMethodInfo(newInstance, RubyMemberFlags.Public, singletonClass));

            singletonClass.AddMethod(context, "members", new RubyLibraryMethodInfo(
                                         new[] { LibraryOverload.Create(new Func <RubyClass, RubyArray>(GetMembers), false, 0, 0) },
                                         RubyMemberFlags.Public,
                                         singletonClass
                                         ));

            for (int i = 0; i < structMembers.Length; i++)
            {
                string getter = structMembers[i];

                cls.AddMethod(context, getter, new RubyCustomMethodInfo(CreateGetter(i), RubyMemberFlags.Public, cls));
                cls.AddMethod(context, getter + '=', new RubyCustomMethodInfo(CreateSetter(i), RubyMemberFlags.Public, cls));
            }
        }
Пример #8
0
 private void LibModuleSingletonMethods(RubyModule /*!*/ module)
 {
     DefineLibraryMethod(module, "bar", (int)RubyMethodAttributes.PublicSingleton, new[] {
         LibraryOverload.Reflect(new Func <RubyModule, string>(Bar)),
     });
 }