public MainPage()
        {
            this.InitializeComponent();

            var setup = new ScriptRuntimeSetup();
            setup.HostType = typeof(DlrHost);
            setup.AddRubySetup();

            var runtime = Ruby.CreateRuntime(setup);
            this.engine = Ruby.GetEngine(runtime);
            this.scope = engine.CreateScope();
            this.scope.SetVariable("Main", this);

            runtime.LoadAssembly(typeof(object).GetTypeInfo().Assembly);
            runtime.LoadAssembly(typeof(TextSetOptions).GetTypeInfo().Assembly);
            runtime.LoadAssembly(typeof(TextAlignment).GetTypeInfo().Assembly);

            string outputText = @"
box = main.find_name('OutputBox')
p box.text_alignment
box.text_alignment = Windows::UI::Xaml::TextAlignment.Right
p box.text_alignment
";
            InputBox.IsSpellCheckEnabled = false;
            OutputBox.IsSpellCheckEnabled = false;
            InputBox.Document.SetText(TextSetOptions.None, outputText);
        }
Beispiel #2
0
        public Ruby()
        {
            //Setup the script engine runtime
            var setup = new ScriptRuntimeSetup();
            setup.LanguageSetups.Add(
                new LanguageSetup(
                    "IronRuby.Runtime.RubyContext, IronRuby",
                    "IronRuby 1.0",
                    new[] { "IronRuby", "Ruby", "rb" },
                    new[] { ".rb" }));
            setup.DebugMode = true;
            
            //Create the runtime, engine, and scope
            runtime = ScriptRuntime.CreateRemote(AppDomain.CurrentDomain, setup);
            engine = runtime.GetEngine("Ruby");
            scope = engine.CreateScope();

            try
            {
                engine.Execute(@"$RGSS_VERSION = " + Program.GetRuntime().GetRGSSVersion(), scope);
                engine.Execute(@"$GAME_DIRECTORY = '" + Program.GetRuntime().GetResourcePaths()[0].Replace(@"\", @"\\") + @"'", scope);
                engine.Execute(@"$GAME_OS_WIN = " + Program.GetRuntime().IsWindowsOS().ToString().ToLower(), scope);
            }
            catch (Exception e)
            {
                Program.Error(e.Message);
            }

            //Load system internals and our Ruby internals
            Console.WriteLine("Loading system");
            //engine.Execute(System.Text.Encoding.UTF8.GetString(Properties.Resources.System), scope);
            string script = System.Text.Encoding.UTF8.GetString(Properties.Resources.System);
            script = script.Substring(1);  //fix for a weird character that shouldn't be there o.O
            Eval(script);

            //Load the adaptable RPG datatypes
            script = System.Text.Encoding.UTF8.GetString(Properties.Resources.RPG);
            script = script.Substring(1);
            Eval(script);

            //Load the version appropriate RPG datatypes
            if (Program.GetRuntime().GetRGSSVersion() == 1)
            {
                script = System.Text.Encoding.UTF8.GetString(Properties.Resources.RPG1);
                script = script.Substring(1);
                Eval(script);
            }
            if (Program.GetRuntime().GetRGSSVersion() == 2)
            {
                script = System.Text.Encoding.UTF8.GetString(Properties.Resources.RPG2);
                script = script.Substring(1);
                Eval(script);
            }
            if (Program.GetRuntime().GetRGSSVersion() == 3)
            {
                script = System.Text.Encoding.UTF8.GetString(Properties.Resources.RPG3);
                script = script.Substring(1);
                Eval(script);
            }
        }
        /// <summary>
        /// Reads setup from .NET configuration system (.config files).
        /// If there is no configuration available returns an empty setup.
        /// </summary>
        public static ScriptRuntimeSetup ReadConfiguration()
        {
            var setup = new ScriptRuntimeSetup();

            Configuration.Section.LoadRuntimeSetup(setup, null);
            return(setup);
        }
        public ScriptEngine GetEngine()
        {
            if (_engine != null)
                return _engine;
            _engine = Python.CreateEngine();

            ScriptRuntimeSetup setup = new ScriptRuntimeSetup();
            setup.DebugMode = true;
            setup.LanguageSetups.Add(Python.CreateLanguageSetup(null));
            ScriptRuntime runtime = new ScriptRuntime(setup);
            _engine = runtime.GetEngineByTypeName(typeof(PythonContext).AssemblyQualifiedName);

            _engine.Runtime.IO.SetOutput(_stream, Encoding.UTF8);
            _engine.Runtime.IO.SetErrorOutput(_stream, Encoding.UTF8);
            string path = Environment.CurrentDirectory;
            string ironPythonLibPath = string.Format(@"{0}\IronPythonLib.zip", path);
            var paths = _engine.GetSearchPaths() as List<string> ?? new List<string>();
            paths.Add(path);
            paths.Add(ironPythonLibPath);
            path = Environment.GetEnvironmentVariable("IRONPYTHONPATH");
            if (!string.IsNullOrEmpty(path))
            {
                var pathStrings = path.Split(';');
                paths.AddRange(pathStrings.Where(p => p.Length > 0));
            }
            _engine.SetSearchPaths(paths.ToArray());
            return _engine;
        }
        public void Cons_NoArg1()
        {
            var srs = new ScriptRuntimeSetup();
            Assert.AreEqual(0, srs.LanguageSetups.Count);

            var sr = new ScriptRuntime(srs);
        }
        static SassFileCompiler()
        {
            _sassModule = new TrashStack<SassModule>(() => {
                var srs = new ScriptRuntimeSetup() {
                    HostType = typeof (ResourceAwareScriptHost),
                    //DebugMode = Debugger.IsAttached
                };
                srs.AddRubySetup();
                var runtime = Ruby.CreateRuntime(srs);
                var engine = runtime.GetRubyEngine();

                // NB: 'R:\' is a garbage path that the PAL override below will
                // detect and attempt to find via an embedded Resource file
                engine.SetSearchPaths(new[] {@"R:/lib/ironruby", @"R:/lib/ruby/1.9.1"});

                var source = engine.CreateScriptSourceFromString(Utility.ResourceAsString("SassAndCoffee.Core.lib.sass_in_one.rb"), "R:/lib/sass_in_one.rb", SourceCodeKind.File);
                var scope = engine.CreateScope();
                source.Execute(scope);
                return new SassModule {
                    PlatformAdaptationLayer = (VirtualFilePAL)runtime.Host.PlatformAdaptationLayer,
                    Engine = scope.Engine.Runtime.Globals.GetVariable("Sass"),
                    SassOption = engine.Execute(@"{:syntax => :sass, :cache_location => ""C:/""}"),
                    ScssOption = engine.Execute(@"{:syntax => :scss, :cache_location => ""C:/""}"),
                    ExecuteRubyCode = code => engine.Execute(code, scope)
                };
            });
        }
Beispiel #7
0
    static void Main(string[] args)
    {
        // set path for dynamic assembly loading
        AppDomain.CurrentDomain.AssemblyResolve +=
            new ResolveEventHandler(ResolveAssembly);

        string path = System.IO.Path.Combine(exe_path, py_path);
        pyscript = System.IO.Path.Combine(path, pyscript);
        pyscript = System.IO.Path.GetFullPath(pyscript); // normalize

        // get runtime
        ScriptRuntimeSetup scriptRuntimeSetup = new ScriptRuntimeSetup();

        LanguageSetup language = Python.CreateLanguageSetup(null);
        language.Options["Debug"] = true;
        scriptRuntimeSetup.LanguageSetups.Add(language);

        ScriptRuntime runtime = new Microsoft.Scripting.Hosting.ScriptRuntime(scriptRuntimeSetup);

        // set sys.argv
        SetPyEnv(runtime, pyscript, args);

        // get engine
        ScriptScope scope = runtime.CreateScope();
        ScriptEngine engine = runtime.GetEngine("python");

        ScriptSource source = engine.CreateScriptSourceFromFile(pyscript);
        source.Compile();

        try {
            source.Execute(scope);
        } catch (IronPython.Runtime.Exceptions.SystemExitException e) {
            Console.WriteLine(e.StackTrace);
        }
    }
        /*!*/
        protected override ScriptRuntime CreateRuntime()
        {
            string root = IronRubyToolsPackage.Instance.IronRubyBinPath;
            string configPath = IronRubyToolsPackage.Instance.IronRubyExecutable + ".config";
            LanguageSetup existingRubySetup = null;
            LanguageSetup rubySetup = Ruby.CreateRubySetup();

            if (File.Exists(configPath)) {
                try {
                    existingRubySetup = GetSetupByName(ScriptRuntimeSetup.ReadConfiguration(configPath), "IronRuby");
                } catch {
                    // TODO: report the error
                }
            }

            if (existingRubySetup != null) {
                var options = new RubyOptions(existingRubySetup.Options);
                rubySetup.Options["StandardLibraryPath"] = NormalizePaths(root, new[] { options.StandardLibraryPath })[0];
                rubySetup.Options["RequiredPaths"] = NormalizePaths(root, options.RequirePaths);
                rubySetup.Options["SearchPaths"] = NormalizePaths(root, options.SearchPaths);
            }

            var runtimeSetup = new ScriptRuntimeSetup();
            runtimeSetup.LanguageSetups.Add(rubySetup);
            return RemoteScriptFactory.CreateRuntime(runtimeSetup);
        }
Beispiel #9
0
        /// <summary>
        /// Creates ScriptRuntime in the current app-domain and initialized according to the the specified settings.
        /// Creates an instance of host class specified in the setup and associates it with the created runtime.
        /// Both Runtime and ScriptHost are collocated in the current app-domain.
        /// </summary>
        public ScriptRuntime(ScriptRuntimeSetup setup)
        {
            ContractUtils.RequiresNotNull(setup, "setup");

            // Do this first, so we detect configuration errors immediately
            DlrConfiguration config = setup.ToConfiguration();

            _setup = setup;

            _host = ReflectionUtils.CreateInstance <ScriptHost>(setup.HostType, setup.HostArguments.ToArray <object>());

            ScriptHostProxy hostProxy = new ScriptHostProxy(_host);

            _manager          = new ScriptDomainManager(hostProxy, config);
            _invariantContext = new InvariantContext(_manager);

            _io      = new ScriptIO(_manager.SharedIO);
            _engines = new Dictionary <LanguageContext, ScriptEngine>();

            bool freshEngineCreated;

            _globals = new ScriptScope(GetEngineNoLockNoNotification(_invariantContext, out freshEngineCreated), _manager.Globals);

            // runtime needs to be all set at this point, host code is called

            _host.SetRuntime(this);
        }
Beispiel #10
0
        public SassTransformerBase(string syntaxOption)
        {
            var pal = new ResourceRedirectionPlatformAdaptationLayer();
            var srs = new ScriptRuntimeSetup
            {
                HostType = typeof(SassCompilerScriptHost),
                HostArguments = new List<object> { pal },
            };
            srs.AddRubySetup();
            var runtime = Ruby.CreateRuntime(srs);
            var engine = runtime.GetRubyEngine();

            // NB: 'R:\{345ED29D-C275-4C64-8372-65B06E54F5A7}' is a garbage path that the PAL override will
            // detect and attempt to find via an embedded Resource file
            engine.SetSearchPaths(new List<string>
                                      {
                                          @"R:\{345ED29D-C275-4C64-8372-65B06E54F5A7}\lib\ironruby",
                                          @"R:\{345ED29D-C275-4C64-8372-65B06E54F5A7}\lib\ruby\1.9.1"
                                      });

            var source = engine.CreateScriptSourceFromString(Utility.ResourceAsString("lib.sass_in_one.rb", typeof(SassCompiler)), SourceCodeKind.File);
            var scope = engine.CreateScope();
            source.Execute(scope);

            sassCompiler = scope.Engine.Runtime.Globals.GetVariable("Sass");
            option = engine.Execute(syntaxOption);
        }
Beispiel #11
0
        /// <summary>
        /// Creates ScriptRuntime in the current app-domain and initialized according to the the specified settings.
        /// Creates an instance of host class specified in the setup and associates it with the created runtime.
        /// Both Runtime and ScriptHost are collocated in the specified app-domain.
        /// </summary>
        public static ScriptRuntime CreateRemote(AppDomain domain, ScriptRuntimeSetup setup)
        {
            ContractUtils.RequiresNotNull(domain, "domain");
#if !CLR2
            return((ScriptRuntime)domain.CreateInstanceAndUnwrap(
                       typeof(ScriptRuntime).Assembly.FullName,
                       typeof(ScriptRuntime).FullName,
                       false,
                       BindingFlags.Default,
                       null,
                       new object[] { setup },
                       null,
                       null
                       ));
#else
            //The API CreateInstanceAndUnwrap is obsolete in Dev10.
            return((ScriptRuntime)domain.CreateInstanceAndUnwrap(
                       typeof(ScriptRuntime).Assembly.FullName,
                       typeof(ScriptRuntime).FullName,
                       false,
                       BindingFlags.Default,
                       null,
                       new object[] { setup },
                       null,
                       null,
                       null
                       ));
#endif
        }
Beispiel #12
0
        public RubyScriptingRuntime() {
            _defaultLanguageSetup = Ruby.CreateRubySetup();

            var setup = new ScriptRuntimeSetup();
            setup.LanguageSetups.Add(_defaultLanguageSetup);
            _scriptingRuntime = new ScriptRuntime(setup);
        }
Beispiel #13
0
        /// <summary>
        /// Creates a ScriptRuntimeSetup object which includes the Python script engine with the specified options.
        /// 
        /// The ScriptRuntimeSetup object can then be additional configured and used to create a ScriptRuntime.
        /// </summary>
        /*!*/
        public static ScriptRuntimeSetup CreateRuntimeSetup(IDictionary<string, object> options)
        {
            ScriptRuntimeSetup setup = new ScriptRuntimeSetup();
            setup.LanguageSetups.Add(CreateLanguageSetup(options));

            if (options != null)
            {
                object value;
                if (options.TryGetValue("Debug", out value) &&
                    value is bool &&
                    (bool)value)
                {
                    setup.DebugMode = true;
                }

                if (options.TryGetValue("PrivateBinding", out value) &&
                    value is bool &&
                    (bool)value)
                {
                    setup.PrivateBinding = true;
                }
            }

            return setup;
        }
        public void Cons_NoArg2()
        {
            var srs = new ScriptRuntimeSetup();
            var sr = new ScriptRuntime(srs);

            Assert.Fail("shouldn't be able to create a runtime without any langsetups");
        }
        /// <summary>
        /// Reads setup from a specified XML stream.
        /// </summary>
        public static ScriptRuntimeSetup ReadConfiguration(Stream configFileStream)
        {
            ContractUtils.RequiresNotNull(configFileStream, "configFileStream");
            var setup = new ScriptRuntimeSetup();

            Configuration.Section.LoadRuntimeSetup(setup, configFileStream);
            return(setup);
        }
 private static LanguageSetup GetSetupByName(ScriptRuntimeSetup/*!*/ setup, string/*!*/ name) {
     foreach (var languageSetup in setup.LanguageSetups) {
         if (languageSetup.Names.IndexOf(name) >= 0) {
             return languageSetup;
         }
     }
     return null;
 }
        internal static ScriptRuntime CreatePythonOnlyRuntime(string[] ids, string[] exts) {
            ScriptRuntimeSetup srs = new ScriptRuntimeSetup();
            srs.LanguageSetups.Add(new LanguageSetup(
                typeof(IronPython.Runtime.PythonContext).AssemblyQualifiedName,
                "python", ids, exts
            ));

            return new ScriptRuntime(srs);
        }
        /// <summary>
        /// Reads setup from .NET configuration system (.config files).
        /// If there is no configuration available returns an empty setup.
        /// </summary>
        public static ScriptRuntimeSetup ReadConfiguration()
        {
#if SILVERLIGHT
            return(new ScriptRuntimeSetup());
#else
            var setup = new ScriptRuntimeSetup();
            Configuration.Section.LoadRuntimeSetup(setup, null);
            return(setup);
#endif
        }
        public void Initialize()
        {
            var setup = new ScriptRuntimeSetup();

            var typeName = typeof (NaggumLanguageContext).AssemblyQualifiedName;
            setup.LanguageSetups.Add(
                new LanguageSetup(typeName, "Naggum", new[] { "naggum" }, new[] { ".naggum" }));
            var runtime = new ScriptRuntime(setup);
            _engine = runtime.GetEngine("naggum");
        }
        static PyControllerFactory()
        {
            _setup = ScriptRuntimeSetup.ReadConfiguration();
            _runtime = new ScriptRuntime(_setup);

            _runtime.LoadAssembly(Assembly.GetExecutingAssembly());

            string path = HttpContext.Current.Server.MapPath("~/App_Data/Controllers.py");
            _runtime.GetEngine("IronPython").ExecuteFile(path, _runtime.Globals);
        }
        /// <summary>
        /// Reads setup from .NET configuration system (.config files).
        /// If there is no configuration available returns an empty setup.
        /// </summary>
        public static ScriptRuntimeSetup ReadConfiguration()
        {
#if FEATURE_CONFIGURATION
            var setup = new ScriptRuntimeSetup();
            Configuration.Section.LoadRuntimeSetup(setup, null);
            return(setup);
#else
            return(new ScriptRuntimeSetup());
#endif
        }
Beispiel #22
0
        /// <summary>
        /// Initialises an instance
        /// </summary>
        /// <param name="languageSetup">Scripting language configuration object</param>
        /// <param name="enableDebugging">Indicates whether script debugging should be enabled</param>
        public Engine(LanguageSetup languageSetup, bool enableDebugging)
        {
            ScriptRuntimeSetup setup = new ScriptRuntimeSetup();
            setup.LanguageSetups.Add(languageSetup);
            setup.DebugMode = enableDebugging;

            var runtime = new ScriptRuntime(setup);
            var engine = runtime.GetEngine(setup.LanguageSetups[0].Names[0]);

            _engine = engine;
            _scope = _engine.CreateScope();
        }
Beispiel #23
0
        public pythonEngine(String pythonFilename)
        {
            // Create a new engine and scope
            ScriptRuntimeSetup setup = new ScriptRuntimeSetup();
            setup.LanguageSetups.Add(IronPython.Hosting.Python.CreateLanguageSetup(null));
            ScriptRuntime runtime = new ScriptRuntime(setup);
            runtime.IO.RedirectToConsole();
            _engine = runtime.GetEngine("IronPython");
            _scope = _engine.CreateScope();

            loadPythonFile(pythonFilename);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="DlrTask"/> class.
        /// </summary>
        /// <param name="factory">The Factory</param>
        /// <param name="xmlElement">The XElement</param>
        /// <param name="taskFactoryLoggingHost">The taskFactoryLoggingHost</param>
        internal DlrTask(DlrTaskFactory factory, XElement xmlElement, IBuildEngine taskFactoryLoggingHost)
        {
            this.xelement = xmlElement;
            this.language = GetLanguage(xmlElement);

            var srs = new ScriptRuntimeSetup();
            srs.LanguageSetups.Add(IronRuby.Ruby.CreateRubySetup());
            srs.LanguageSetups.Add(IronPython.Hosting.Python.CreateLanguageSetup(null));
            var runtime = new ScriptRuntime(srs);
            this.engine = runtime.GetEngineByFileExtension(this.language);
            this.scope = this.engine.CreateScope();
            this.scope.log = this.Log;
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            ScriptRuntimeSetup setup = new ScriptRuntimeSetup();
            setup.LanguageSetups.Add(AplusCore.Runtime.AplusLanguageContext.LanguageSetup);

            ScriptRuntime dlrRuntime = new ScriptRuntime(setup);
            _engine = dlrRuntime.GetEngine(@"A+");
            _ms = new MemoryStream();
            var sw = new StreamWriter(_ms);
            dlrRuntime.IO.SetErrorOutput(_ms, sw);
            dlrRuntime.IO.SetOutput(_ms, sw);

            _scope = _engine.CreateScope();
        }
Beispiel #26
0
 public static ScriptRuntimeSetup LoadFromAssemblies(IEnumerable<Assembly> assemblies) {
     var setup = new ScriptRuntimeSetup();
     foreach (var assembly in assemblies) {
         foreach (DynamicLanguageProviderAttribute attribute in assembly.GetCustomAttributes(typeof(DynamicLanguageProviderAttribute), false)) {
             setup.LanguageSetups.Add(new LanguageSetup(
                 attribute.LanguageContextType.AssemblyQualifiedName,
                 attribute.DisplayName,
                 attribute.Names,
                 attribute.FileExtensions
             ));
         }
     }
     return setup;
 }
Beispiel #27
0
 /// <summary>
 /// Creates ScriptRuntime in the current app-domain and initialized according to the the specified settings.
 /// Creates an instance of host class specified in the setup and associates it with the created runtime.
 /// Both Runtime and ScriptHost are collocated in the specified app-domain.
 /// </summary>
 public static ScriptRuntime CreateRemote(AppDomain domain, ScriptRuntimeSetup setup)
 {
     ContractUtils.RequiresNotNull(domain, nameof(domain));
     return((ScriptRuntime)domain.CreateInstanceAndUnwrap(
                typeof(ScriptRuntime).Assembly.FullName,
                typeof(ScriptRuntime).FullName,
                false,
                BindingFlags.Default,
                null,
                new object[] { setup },
                null,
                null
                ));
 }
Beispiel #28
0
        public static ScriptRuntimeSetup TryParseFile()
        {
            Stream configFile = Package.GetFile(_languagesConfigFile);
            if (configFile == null) {
                return null;
            }

            var result = new ScriptRuntimeSetup();
            try {
                XmlReader reader = XmlReader.Create(configFile);
                reader.MoveToContent();
                if (!reader.IsStartElement("Languages")) {
                    throw new ConfigFileException("expected 'Configuration' root element", _languagesConfigFile);
                }

                while (reader.Read()) {
                    if (reader.NodeType != XmlNodeType.Element || reader.Name != "Language") {
                        continue;
                    }
                    string context = null, assembly = null, exts = null;
                    while (reader.MoveToNextAttribute()) {
                        switch (reader.Name) {
                            case "languageContext":
                                context = reader.Value;
                                break;
                            case "assembly":
                                assembly = reader.Value;
                                break;
                            case "extensions":
                                exts = reader.Value;
                                break;
                        }
                    }

                    if (context == null || assembly == null || exts == null) {
                        throw new ConfigFileException("expected 'Language' element to have attributes 'languageContext', 'assembly', 'extensions'", _languagesConfigFile);
                    }

                    string[] extensions = exts.Split(',');
                    result.LanguageSetups.Add(new LanguageSetup(context + ", " + assembly, String.Empty, extensions, extensions));
                }
            } catch (ConfigFileException cfe) {
                throw cfe;
            } catch (Exception ex) {
                throw new ConfigFileException(ex.Message, _languagesConfigFile, ex);
            }

            return result;
        }
Beispiel #29
0
        /// <summary>
        /// Initialize static scripting API objects
        /// </summary>
        static PyFilter()
        {
            _setup = ScriptRuntimeSetup.ReadConfiguration();
            _runtime = new ScriptRuntime(_setup);

            //make System and the current assembly availible to the scripts
            _runtime.LoadAssembly(Assembly.GetExecutingAssembly());
            _runtime.LoadAssembly(Assembly.GetAssembly(typeof(DateTime)));

            //assume default of App_Data/filters.py, but allow for overwriting
            string path = RootPath ?? HttpContext.Current.Server.MapPath("~/App_Data/");
            ScriptEngine engine = _runtime.GetEngine("IronPython");
            engine.SetSearchPaths(new string[] { path });
            engine.ExecuteFile(Path.Combine(path, ScriptFile ?? "filters.py"), _runtime.Globals);
        }
        public void Setup()
        {
            ScriptRuntimeSetup setup = new ScriptRuntimeSetup();
            setup.LanguageSetups.Add(AplusCore.Runtime.AplusLanguageContext.LanguageSetup);

            ScriptRuntime dlrRuntime = new ScriptRuntime(setup);
            this.engine = dlrRuntime.GetEngine("A+");

            ScriptRuntimeSetup setupUni = new ScriptRuntimeSetup();
            setupUni.LanguageSetups.Add(AplusCore.Runtime.AplusLanguageContext.LanguageSetup);
            setupUni.Options.Add("LexerMode", AplusCore.Compiler.LexerMode.UNI);

            ScriptRuntime dlrRuntimeUni = new ScriptRuntime(setupUni);
            this.engineUni = dlrRuntimeUni.GetEngine("A+");
        }
Beispiel #31
0
        /// <summary>
        /// Creates a ScriptRuntimeSetup object which includes the Lua script engine with the specified options.
        /// The ScriptRuntimeSetup object can then be additionally configured and used to create a ScriptRuntime.
        /// </summary>
        public static ScriptRuntimeSetup CreateRuntimeSetup(IDictionary<string, object> options = null)
        {
            var scriptRuntimeSetup = new ScriptRuntimeSetup();
            scriptRuntimeSetup.LanguageSetups.Add(Lua.CreateLanguageSetup(options));
            if (options != null)
            {
                object obj;

                if (options.TryGetValue("Debug", out obj) && obj is bool && (bool)obj)
                    scriptRuntimeSetup.DebugMode = true;

                if (options.TryGetValue("PrivateBinding", out obj) && obj is bool && (bool)obj)
                    scriptRuntimeSetup.PrivateBinding = true;
            }
            return scriptRuntimeSetup;
        }
Beispiel #32
0
        private void Form1_Load(object sender, EventArgs e)
        {
            codeEditorControl1.Document.Text = "print 'Hello World'";

            ScriptRuntimeSetup setup = new ScriptRuntimeSetup();
            setup.LanguageProviders = new[]
                                          {
                                              new LanguageProviderSetup("IronPython.Runtime.PythonContext", "IronPython", ".py", "ironpython")
                                          };
            ScriptRuntime runtime = ScriptRuntime.Create(setup);
            ScriptEngine engine = runtime.GetEngine("IronPython");
            foreach (string s in engine.GetRegisteredExtensions())
            {
                System.Console.WriteLine(s);
            }
        }
Beispiel #33
0
        ///<summary>
        ///</summary>
        ///<param name="runtimeAssembyTypes"></param>
        ///<param name="interpretedMode"></param>
        ///<param name="debugMode"></param>
        ///<returns></returns>
        public static ScriptRuntime CreateIronRubyRuntime(IEnumerable<Type> runtimeAssembyTypes, bool interpretedMode, bool debugMode)
        {
            var rubySetup = Ruby.CreateRubySetup();
            rubySetup.Options["InterpretedMode"] = interpretedMode;

            var runtimeSetup = new ScriptRuntimeSetup();
            runtimeSetup.LanguageSetups.Add(rubySetup);
            runtimeSetup.DebugMode = debugMode;

            var scriptRuntime = Ruby.CreateRuntime(runtimeSetup);

            foreach (var type in runtimeAssembyTypes)
            {
                scriptRuntime.LoadAssembly(type.Assembly);
            }
            return scriptRuntime;
        }
Beispiel #34
0
    protected override ConsoleOptions ParseOptions(string/*!*/[]/*!*/ args, ScriptRuntimeSetup/*!*/ runtimeSetup, LanguageSetup/*!*/ languageSetup)
    {
        var rubyOptions = (RubyConsoleOptions)base.ParseOptions(args, runtimeSetup, languageSetup);
        if (rubyOptions == null) {
            return null;
        }

        if (rubyOptions.ChangeDirectory != null) {
            Environment.CurrentDirectory = rubyOptions.ChangeDirectory;
        }

        if (rubyOptions.DisplayVersion && (rubyOptions.Command != null || rubyOptions.FileName != null)) {
            Console.WriteLine(RubyContext.MakeDescriptionString(), Style.Out);
        }

        return rubyOptions;
    }
        public RubyEngine(object appScope)
        {
            var runtimeSetup = new ScriptRuntimeSetup();
            runtimeSetup
                .LanguageSetups
                .Add(new LanguageSetup("IronRuby.Runtime.RubyContext, IronRuby",
                                       "IronRuby 1.0",
                                       new[] { "IronRuby", "Ruby", "rb" },
                                       new[] { ".rb" }));

            runtime = ScriptRuntime.CreateRemote(AppDomain.CurrentDomain, runtimeSetup);

            scope = runtime.CreateScope();
            scope.SetVariable("app", appScope);

            engine = runtime.GetEngine("IronRuby");
        }
Beispiel #36
0
        public BonsaiTestClass()
        {
            ScriptRuntimeSetup runtimeSetup = new ScriptRuntimeSetup() {
                DebugMode = true,
                LanguageSetups = {
                      new LanguageSetup(
                        typeof(BonsaiContext).AssemblyQualifiedName,
                        "Bonsai",
                        new string[] {"Bonsai"},
                        new string[] {".bon"})
                }
            };

            ScriptRuntime runtime = new ScriptRuntime(runtimeSetup);
            ScriptScope global = runtime.CreateScope();
            scriptEngineInstance = runtime.GetEngineByTypeName(typeof(BonsaiContext).AssemblyQualifiedName);
        }
Beispiel #37
0
    protected override ConsoleOptions ParseOptions(string/*!*/[]/*!*/ args, ScriptRuntimeSetup/*!*/ runtimeSetup, LanguageSetup/*!*/ languageSetup)
    {
        var rubyOptions = (RubyConsoleOptions)base.ParseOptions(args, runtimeSetup, languageSetup);
        if (rubyOptions == null) {
            return null;
        }

        if (rubyOptions.ChangeDirectory != null) {
            Environment.CurrentDirectory = rubyOptions.ChangeDirectory;
        }

        if (rubyOptions.Introspection || rubyOptions.Command == null && rubyOptions.FileName == null) {
            PrintHelp();
            return null;
        }

        return rubyOptions;
    }
        /// <summary>
        /// Creates ScriptRuntime in the current app-domain and initialized according to the the specified settings.
        /// Creates an instance of host class specified in the setup and associates it with the created runtime.
        /// Both Runtime and ScriptHost are collocated in the current app-domain.
        /// </summary>
        public ScriptRuntime(ScriptRuntimeSetup setup)
        {
            ContractUtils.RequiresNotNull(setup, "setup");

            // Do this first, so we detect configuration errors immediately
            DlrConfiguration config = setup.ToConfiguration();

            _setup = setup;

            try {
                _host = (ScriptHost)Activator.CreateInstance(setup.HostType, setup.HostArguments.ToArray <object>());
            } catch (TargetInvocationException e) {
                throw new InvalidImplementationException(Strings.InvalidCtorImplementation(setup.HostType, e.InnerException.Message), e.InnerException);
            } catch (Exception e) {
                throw new InvalidImplementationException(Strings.InvalidCtorImplementation(setup.HostType, e.Message), e);
            }

            ScriptHostProxy hostProxy = new ScriptHostProxy(_host);

            _manager          = new ScriptDomainManager(hostProxy, config);
            _invariantContext = new InvariantContext(_manager);

            _io      = new ScriptIO(_manager.SharedIO);
            _engines = new Dictionary <LanguageContext, ScriptEngine>();

            bool freshEngineCreated;

            _globals = new ScriptScope(GetEngineNoLockNoNotification(_invariantContext, out freshEngineCreated), _manager.Globals);

            // runtime needs to be all set at this point, host code is called

            _host.SetRuntime(this);

            object noDefaultRefs;

            if (!setup.Options.TryGetValue("NoDefaultReferences", out noDefaultRefs) || Convert.ToBoolean(noDefaultRefs) == false)
            {
                LoadAssembly(typeof(string).GetTypeInfo().Assembly);
                LoadAssembly(typeof(System.Diagnostics.Debug).GetTypeInfo().Assembly);
            }
        }
Beispiel #39
0
 /// <summary>
 /// Creates a new runtime with languages set up according to the current application configuration
 /// (using System.Configuration).
 /// </summary>
 public static ScriptRuntime CreateFromConfiguration()
 {
     return(new ScriptRuntime(ScriptRuntimeSetup.ReadConfiguration()));
 }