Ejemplo n.º 1
0
        private ScriptEngine CreateAndInitEngine()
        {
            var engine = Ruby.CreateEngine();

            engine.Runtime.LoadAssembly(Assembly.GetExecutingAssembly());

            // set library/assembly search paths
            // (used by require and load_assembly)
            var libPathProvider = new LibraryPathFile(m_pathResolver, @"path.txt");

            engine.SetSearchPaths(libPathProvider.Paths);

            // Expose global objects
            var ctx = HostingHelpers.GetLanguageContext(engine) as RubyContext;

            ctx.DefineReadOnlyGlobalVariable(
                "onError",
                new Action <MutableString, RubyArray>(TriggerErrorEventFromRuby) // #onError(message, backtrace)
                );

            // HACK: needed to set $0 == <main script filename>
            ctx.DefineGlobalVariable("0", Path.GetFileName(MainScript));
            ctx.DefineReadOnlyGlobalVariable("pr", m_pathResolver);

            // Create initial script source
            m_scriptSrc = engine.CreateScriptSourceFromFile(
                MainScript,
                Encoding.UTF8,
                SourceCodeKind.File
                );

            // Set new IO streams
            RedirectIOStreams(engine);
            return(engine);
        }
Ejemplo n.º 2
0
        private ScriptEngine CreateAndInitEngine()
        {
            var engine = Ruby.CreateEngine();
              engine.Runtime.LoadAssembly(Assembly.GetExecutingAssembly());

              // set library/assembly search paths
              // (used by require and load_assembly)
              var libPathProvider = new LibraryPathFile(m_pathResolver, @"path.txt");
              engine.SetSearchPaths(libPathProvider.Paths);

              // Expose global objects
              var ctx = HostingHelpers.GetLanguageContext(engine) as RubyContext;
              ctx.DefineReadOnlyGlobalVariable(
            "onError",
            new Action<MutableString, RubyArray>(TriggerErrorEventFromRuby) // #onError(message, backtrace)
              );

              // HACK: needed to set $0 == <main script filename>
              ctx.DefineGlobalVariable("0", Path.GetFileName(MainScript));
              ctx.DefineReadOnlyGlobalVariable("pr", m_pathResolver);

              // Create initial script source
              m_scriptSrc = engine.CreateScriptSourceFromFile(
            MainScript,
            Encoding.UTF8,
            SourceCodeKind.File
              );

              // Set new IO streams
              RedirectIOStreams(engine);
              return engine;
        }