Exemplo n.º 1
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)
         });
     }
 }
Exemplo n.º 2
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);
     }
 }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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));
            }
        }