public static void MultiLanguageLoad() { var runtimeSetup = new ScriptRuntimeSetup(); var pythonSetup = new LanguageSetup( typeName: "IronPython.Runtime.PythonContext, IronPython", displayName: "IronPython", names: new[] { "IronPython", "Python", "py" }, fileExtensions: new[] { ".py" }); runtimeSetup.LanguageSetups.Add(pythonSetup); var rubySetup = new LanguageSetup( typeName: "IronRuby.Runtime.RubyContext, IronRuby", displayName: "IronRuby", names: new[] { "IronRuby", "Ruby", "rb" }, fileExtensions: new[] { ".rb" }); runtimeSetup.LanguageSetups.Add(rubySetup); ScriptRuntime runtimeObject = new ScriptRuntime(runtimeSetup); ScriptEngine pythonEngine = runtimeObject.GetEngine("Python"); ScriptEngine rubyEngine = runtimeObject.GetEngineByFileExtension(".rb"); pythonEngine.Execute("print 'Hello from Python!'"); rubyEngine.Execute("puts 'Hello from Ruby!'"); }
public RubyScriptingRuntime() { _defaultLanguageSetup = Ruby.CreateRubySetup(); var setup = new ScriptRuntimeSetup(); setup.LanguageSetups.Add(_defaultLanguageSetup); _scriptingRuntime = new ScriptRuntime(setup); }
internal Host(LanguageSetup language, string languageName, bool enableDebug) { _output = new MemoryStream(); _error = new MemoryStream(); //var configFile = Path.GetFullPath(Uri.UnescapeDataString(new Uri(typeof(Host).Assembly.CodeBase).AbsolutePath)) + ".config"; //_runtime = new ScriptRuntime(ScriptRuntimeSetup.ReadConfiguration(configFile)); ScriptRuntimeSetup setup = new ScriptRuntimeSetup(); if (enableDebug) { language.Options["Debug"] = Microsoft.Scripting.Runtime.ScriptingRuntimeHelpers.True; setup.DebugMode = true; } setup.LanguageSetups.Add(language); _runtime = new ScriptRuntime(setup); _engine = _runtime.GetEngine(languageName); _runtime.IO.SetOutput(_output, new StreamWriter(_output)); _runtime.IO.SetErrorOutput(_error, new StreamWriter(_error)); _theScope = _engine.CreateScope(); _theScope.SetVariable("_host", this); }
public void RubyHosting5() { // app-domain creation: if (_driver.PartialTrust) { return; } AppDomain domain = AppDomain.CreateDomain("foo"); var rs = ScriptRuntimeSetup.ReadConfiguration(); LanguageSetup ls = rs.GetRubySetup(); Debug.Assert(ls.Names.IndexOf("IronRuby") != -1); var newSetup = new ScriptRuntimeSetup(); newSetup.AddRubySetup((s) => { s.Options["LibraryPaths"] = ls.Options["LibraryPaths"]; }); ScriptRuntime runtime = ScriptRuntime.CreateRemote(domain, newSetup); ScriptEngine engine = runtime.GetRubyEngine(); Assert(engine.RequireFile("fcntl") == true); Assert(engine.Execute <bool>("Object.constants.include?(:Fcntl)") == true); }
/// <exception cref="InvalidOptionException">On error.</exception> public void Parse(string[] args, ScriptRuntimeSetup setup, LanguageSetup languageSetup, PlatformAdaptationLayer platform) { ContractUtils.RequiresNotNull(args, "args"); ContractUtils.RequiresNotNull(setup, "setup"); ContractUtils.RequiresNotNull(languageSetup, "languageSetup"); ContractUtils.RequiresNotNull(platform, "platform"); _args = args; _runtimeSetup = setup; _languageSetup = languageSetup; _platform = platform; _current = 0; try { BeforeParse(); while (_current < args.Length) { ParseArgument(args[_current++]); } AfterParse(); } finally { _args = null; _runtimeSetup = null; _languageSetup = null; _platform = null; _current = -1; } }
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)); }
public TestRuntime(Driver /*!*/ driver, TestCase /*!*/ testCase) { _driver = driver; _testName = testCase.Name; if (_driver.IsDebug) { Environment.SetEnvironmentVariable("DLR_AssembliesFileName", _testName); } var runtimeSetup = ScriptRuntimeSetup.ReadConfiguration(); LanguageSetup langaugeSetup = null; foreach (var language in runtimeSetup.LanguageSetups) { if (language.TypeName == typeof(RubyContext).AssemblyQualifiedName) { langaugeSetup = language; break; } } // TODO: dynamic modules with symbols are not available in partial trust runtimeSetup.DebugMode = !driver.PartialTrust; langaugeSetup.Options["InterpretedMode"] = _driver.Interpret; langaugeSetup.Options["Verbosity"] = 2; langaugeSetup.Options["Compatibility"] = testCase.Compatibility; _env = Ruby.CreateRuntime(runtimeSetup); _engine = Ruby.GetEngine(_env); _context = Ruby.GetExecutionContext(_engine); }
public static void PassingVariablesToCompiledCode( string question, object correctResponse) { var runtimeSetup = new ScriptRuntimeSetup(); var languageSetup = new LanguageSetup( "IronPython.Runtime.PythonContext, IronPython", "IronPython", new[] { "Python" }, new[] { ".py" }); runtimeSetup.LanguageSetups.Add(languageSetup); var runtime = new ScriptRuntime(runtimeSetup); ScriptEngine engine = runtime.GetEngine("Python"); ScriptSource source = engine.CreateScriptSourceFromString(@" import Question import CorrectResponse input(Question) == CorrectResponse "); CompiledCode AskQuestion = source.Compile(); runtime.Globals.SetVariable("Question", question); runtime.Globals.SetVariable( "CorrectResponse", correctResponse); Console.WriteLine("You chose... {0}", AskQuestion.Execute <bool>() ? "wisely." : "poorly"); }
//todo[lt3] doesn't work static void Main(string[] args) { //ScriptRuntime env = ScriptRuntime.CreateFromConfiguration(); ScriptRuntimeSetup setup = new ScriptRuntimeSetup(); LanguageSetup lsetup = new LanguageSetup( typeof(ClojureContext).AssemblyQualifiedName, ClojureContext.ClojureDisplayName, ClojureContext.ClojureNames.Split(new Char[] { ';' }), ClojureContext.ClojureFileExtensions.Split(new Char[] { ';' })); setup.LanguageSetups.Add(lsetup); ScriptRuntime env = new ScriptRuntime(setup); ScriptEngine curEngine = env.GetEngine("clj"); Console.WriteLine("CurrentEngine: {0}", curEngine.LanguageVersion.ToString()); ScriptScope scope = curEngine.CreateScope(); Console.WriteLine("Scope: {0}", scope.GetItems()); Console.WriteLine("REPL started, q for quit"); var argList = new List <string>(args); string t = "xx"; Func <string> getCmd = () => { Console.Write("> "); if (argList.Count() > 0) { var r = argList[0]; argList.RemoveAt(0); //lt2 rf Pull return(r); } return(Console.ReadLine()); }; Func <string, object> execute_inner = (tt => scope.Engine.Execute(tt, scope)); bool failSafe = false; while ((t = getCmd()) != "q") { object r; if (failSafe) { try { r = (t == "" ? null : execute_inner(t)); } catch (Exception ex) { r = ex; throw; //xx } } else { r = execute_inner(t); } PrintResult(r); } }
protected override void ConfigureIronRuby(LanguageSetup languageSetup, IList<string> libraryPaths) { libraryPaths.Add(Path.Combine(pluginBaseDirectory.FullName, "Scripts")); libraryPaths.Add(Path.Combine(pluginBaseDirectory.FullName, @"libs\rspec-1.2.7\lib")); #if DEBUG libraryPaths.Add(Path.Combine(pluginBaseDirectory.FullName, @"..\libs\rspec-1.2.7\lib")); #endif }
protected override void ConfigureIronRuby(LanguageSetup languageSetup, IList <string> libraryPaths) { libraryPaths.Add(Path.Combine(pluginBaseDirectory.FullName, "Scripts")); libraryPaths.Add(Path.Combine(pluginBaseDirectory.FullName, @"libs\rspec-1.2.7\lib")); #if DEBUG libraryPaths.Add(Path.Combine(pluginBaseDirectory.FullName, @"..\libs\rspec-1.2.7\lib")); #endif }
public virtual int Run(string[] args) { var runtimeSetup = CreateRuntimeSetup(); var options = new ConsoleHostOptions(); _optionsParser = new ConsoleHostOptionsParser(options, runtimeSetup); try { ParseHostOptions(args); } catch (InvalidOptionException e) { Console.Error.WriteLine("Invalid argument: " + e.Message); return(_exitCode = 1); } SetEnvironment(); string provider = GetLanguageProvider(runtimeSetup); LanguageSetup languageSetup = null; foreach (var language in runtimeSetup.LanguageSetups) { if (language.TypeName == provider) { languageSetup = language; } } if (languageSetup == null) { // the language doesn't have a setup -> create a default one: languageSetup = new LanguageSetup(Provider.AssemblyQualifiedName, Provider.Name); runtimeSetup.LanguageSetups.Add(languageSetup); } // inserts search paths for all languages (/paths option): InsertSearchPaths(runtimeSetup.Options, Options.SourceUnitSearchPaths); _languageOptionsParser = CreateOptionsParser(); try { _languageOptionsParser.Parse(Options.IgnoredArgs.ToArray(), runtimeSetup, languageSetup, PlatformAdaptationLayer); } catch (InvalidOptionException e) { Console.Error.WriteLine(e.Message); return(_exitCode = -1); } _runtime = new ScriptRuntime(runtimeSetup); try { _engine = _runtime.GetEngineByTypeName(provider); } catch (Exception e) { Console.Error.WriteLine(e.Message); return(_exitCode = 1); } Execute(); return(_exitCode); }
private static void initAsNeeded() { if (_runtime != null) { return; } BugFixer.Run(); DebugUtil.Trigger(); string langQName = typeof(IronPython.Runtime.PythonContext).AssemblyQualifiedName; var langSetup = new LanguageSetup(langQName, "IronPython", new string[] { "IronPython", "Python", "py" }, new string[] { ".py" }); var setup = new ScriptRuntimeSetup(); langSetup.ExceptionDetail = true; // options can be found in ironpython2-ipy-2.7.7\Languages\IronPython\IronPython\Runtime\PythonOptions.cs langSetup.Options["Optimize"] = false; langSetup.Options["StripDocStrings"] = false; langSetup.Options["Frames"] = true; langSetup.Options["Tracing"] = true; // setup.LanguageSetups.Add(langSetup); //this is responsible for python being able to access private members on CLR objects: setup.PrivateBinding = true; _runtime = new ScriptRuntime(setup); _engine = _runtime.GetEngine("IronPython"); //This works for the simple purpose of creating a __main__ module //inspect.stack() should work after doing this. //Not sure if there's a better way. //This solution is from: //https://stackoverflow.com/questions/8264596/how-do-i-set-name-to-main-when-using-ironpython-hosted var pco = (IronPython.Compiler.PythonCompilerOptions)_engine.GetCompilerOptions(); pco.ModuleName = "__main__"; pco.Module |= IronPython.Runtime.ModuleOptions.Initialize; var source = Engine.CreateScriptSourceFromString(@"'''This is the __main__ module'''"); CompiledCode compiled = source.Compile(pco); mainScope = CreateScope(); compiled.Execute(mainScope); //more options string[] searchpaths = new string[] { System.IO.Path.Combine(Util.ModBasePath, "IronPython-2.7.7/Lib/"), System.IO.Path.Combine(Util.ModBasePath, "PythonModules/") }; _engine.SetSearchPaths(searchpaths); _runtime.LoadAssembly(System.Reflection.Assembly.GetExecutingAssembly()); _runtime.LoadAssembly(typeof(Verse.Game).Assembly); }
public override void Reset(ScriptScope scope) { var setup = new ScriptRuntimeSetup(); var ls = new LanguageSetup(typeof(PythonContext).AssemblyQualifiedName, "Python", new[] { "py" }, new[] { ".py" }); setup.LanguageSetups.Add(ls); var runtime = new ScriptRuntime(setup); _engine = runtime.GetEngine("py"); _scope = scope == null?_engine.Runtime.CreateScope() : scope; }
/// <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(); }
private static IList <string> GetIronRubyLibraryPaths(LanguageSetup languageSetup) { List <string> libraryPaths = new List <string>(); object value; if (languageSetup.Options.TryGetValue("LibraryPaths", out value)) { libraryPaths.AddRange(((string)value).Split(';')); } return(libraryPaths); }
private void ConfigureIronRuby(ScriptRuntimeSetup scriptRuntimeSetup) { LanguageSetup languageSetup = GenericCollectionUtils.Find(scriptRuntimeSetup.LanguageSetups, x => x.Names.Contains("IronRuby")); if (languageSetup == null) { return; } IList <string> libraryPaths = GetIronRubyLibraryPaths(languageSetup); ConfigureIronRuby(languageSetup, libraryPaths); CanonicalizeLibraryPaths(libraryPaths); SetIronRubyLibraryPaths(languageSetup, libraryPaths); }
/// <summary> /// Creates the language runtime to be used in hosting. /// </summary> /// <returns></returns> public static ScriptRuntime CreateRuntime() { string[] QsNames = { "QuantitySystem", "Qs" }; string[] QsExtensions = { ".Qs" }; string QsType = typeof(QsContext).FullName + ", " + typeof(QsContext).Assembly.FullName; LanguageSetup QsSetup = new LanguageSetup(QsType, "Quantity System Runtime", QsNames, QsExtensions); ScriptRuntimeSetup srs = new ScriptRuntimeSetup(); srs.LanguageSetups.Add(QsSetup); ScriptRuntime sr = new ScriptRuntime(srs); return(sr); }
/// <summary> /// Creates a LanguageSetup object which includes the Lua script engine with the specified options. /// The LanguageSetup object can be used with other LanguageSetup objects from other languages to configure a ScriptRuntimeSetup object. /// </summary> public static LanguageSetup CreateLanguageSetup(IDictionary<string, object> options = null) { var languageSetup = new LanguageSetup( typeof(LuaContext).AssemblyQualifiedName, "IronLua", "IronLua;Lua;lua".Split(';'), ".lua".Split(';') ); if (options != null) { foreach (KeyValuePair<string, object> keyValuePair in options) languageSetup.Options.Add(keyValuePair.Key, keyValuePair.Value); } return languageSetup; }
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; }
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; }
public PythonObject(string[] args) { ScriptRuntimeSetup runtimeSetup = ScriptRuntimeSetup.ReadConfiguration(); ConsoleHostOptions options = new ConsoleHostOptions(); _optionsParser = new ConsoleHostOptionsParser(options, runtimeSetup); string provider = GetLanguageProvider(runtimeSetup); LanguageSetup languageSetup = null; foreach (LanguageSetup language in runtimeSetup.LanguageSetups) { if (language.TypeName == provider) { languageSetup = language; } } if (languageSetup == null) { // the language doesn't have a setup -> create a default one: languageSetup = new LanguageSetup(Provider.AssemblyQualifiedName, Provider.Name); runtimeSetup.LanguageSetups.Add(languageSetup); } // inserts search paths for all languages (/paths option): InsertSearchPaths(runtimeSetup.Options, Options.SourceUnitSearchPaths); _languageOptionsParser = new OptionsParser<ConsoleOptions>(); try { _languageOptionsParser.Parse(Options.IgnoredArgs.ToArray(), runtimeSetup, languageSetup, PlatformAdaptationLayer.Default); } catch (InvalidOptionException e) { Console.Error.WriteLine(e.Message); } _runtime = new ScriptRuntime(runtimeSetup); try { _engine = _runtime.GetEngineByTypeName(provider); } catch (Exception e) { Console.Error.WriteLine(e.Message); } _runtime.LoadAssembly(System.Reflection.Assembly.GetExecutingAssembly()); _runtime.LoadAssembly(provider.GetType().Assembly); _runtime.LoadAssembly(PythonStringIO.StringIO().GetType().Assembly); _scope= _engine.CreateScope(); RunCommandLine(args); }
/*!*/ public static LanguageSetup CreateLanguageSetup(IDictionary<string, object> options) { var setup = new LanguageSetup( typeof(ClojureContext).AssemblyQualifiedName, ClojureContext.ClojureDisplayName, ClojureContext.ClojureNames.Split(';'), ClojureContext.ClojureFileExtensions.Split(';') ); if (options != null) { foreach (var entry in options) { setup.Options.Add(entry.Key, entry.Value); } } return setup; }
/// <summary> /// Creates a LanguageSetup object which includes the Python script engine with the specified options. /// /// The LanguageSetup object can be used with other LanguageSetup objects from other languages to /// configure a ScriptRuntimeSetup object. /// </summary> public static LanguageSetup /*!*/ CreateLanguageSetup(IDictionary <string, object> options) { var setup = new LanguageSetup( typeof(PythonContext).AssemblyQualifiedName, PythonContext.IronPythonDisplayName, PythonContext.IronPythonNames.Split(';'), PythonContext.IronPythonFileExtensions.Split(';') ); if (options != null) { foreach (var entry in options) { setup.Options.Add(entry.Key, entry.Value); } } return(setup); }
/// <summary> /// Creates a LanguageSetup Object which includes the Essence script engine with the specified options. /// /// The LanguageSetup Object can be used with other LanguageSetup objects from other languages to /// configure a ScriptRuntimeSetup Object. /// </summary> public static LanguageSetup CreateLanguageSetup(IDictionary <String, Object> options) { var setup = new LanguageSetup( typeof(EssenceSharpContext).AssemblyQualifiedName, EssenceSharpContext.EssenceSharpDisplayName, EssenceSharpContext.EssenceSharpNames.Split(';'), EssenceSharpContext.EssenceSharpFileExtensions.Split(';') ); if (options != null) { foreach (var entry in options) { setup.Options.Add(entry.Key, entry.Value); } } return(setup); }
/// <summary> /// Creates a LanguageSetup object which includes the Python script engine with the specified options. /// /// The LanguageSetup object can be used with other LanguageSetup objects from other languages to /// configure a ScriptRuntimeSetup object. /// </summary> /*!*/ public static LanguageSetup CreateLanguageSetup(IDictionary<string, object> options) { var setup = new LanguageSetup( typeof(TotemContext).AssemblyQualifiedName, "IronTotem", new[] { "totem" }, new[] { "totem" } ); if (options != null) { foreach (var entry in options) { setup.Options.Add(entry.Key, entry.Value); } } return setup; }
public static void ReturnScalarFromScript() { var runtimeSetup = new ScriptRuntimeSetup(); var languageSetup = new LanguageSetup( "IronPython.Runtime.PythonContext, IronPython", "IronPython", new[] { "Python" }, new[] { ".py" }); runtimeSetup.LanguageSetups.Add(languageSetup); var runtime = new ScriptRuntime(runtimeSetup); ScriptEngine engine = runtime.GetEngine("Python"); string name = engine.Execute( "raw_input('What is your name? ')"); int age = engine.Execute <int>( "input('How old are you? ')"); Console.WriteLine( "Wow, {0} is only {1} years old!", name, age); }
static void Main(string[] args) { //ScriptRuntime env = ScriptRuntime.CreateFromConfiguration(); ScriptRuntimeSetup setup = new ScriptRuntimeSetup(); LanguageSetup lsetup = new LanguageSetup( typeof(ClojureContext).AssemblyQualifiedName, ClojureContext.ClojureDisplayName, ClojureContext.ClojureNames.Split(new Char[]{';'}), ClojureContext.ClojureFileExtensions.Split(new Char[] { ';' })); setup.LanguageSetups.Add(lsetup); ScriptRuntime env = new ScriptRuntime(setup); ScriptEngine curEngine = env.GetEngine("clj"); Console.WriteLine("CurrentEngine: {0}", curEngine.LanguageVersion.ToString()); ScriptScope scope = curEngine.CreateScope(); Console.WriteLine("Scope: {0}", scope.GetItems()); Console.ReadLine(); }
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); } }
static void Main(string[] args) { //ScriptRuntime env = ScriptRuntime.CreateFromConfiguration(); ScriptRuntimeSetup setup = new ScriptRuntimeSetup(); LanguageSetup lsetup = new LanguageSetup( typeof(ClojureContext).AssemblyQualifiedName, ClojureContext.ClojureDisplayName, ClojureContext.ClojureNames.Split(new Char[] { ';' }), ClojureContext.ClojureFileExtensions.Split(new Char[] { ';' })); setup.LanguageSetups.Add(lsetup); ScriptRuntime env = new ScriptRuntime(setup); ScriptEngine curEngine = env.GetEngine("clj"); Console.WriteLine("CurrentEngine: {0}", curEngine.LanguageVersion.ToString()); ScriptScope scope = curEngine.CreateScope(); Console.WriteLine("Scope: {0}", scope.GetItems()); Console.ReadLine(); }
protected override ConsoleOptions ParseOptions(string[] args, ScriptRuntimeSetup runtimeSetup, LanguageSetup languageSetup) { #if !SILVERLIGHT languageSetup.Options["ApplicationBase"] = AppDomain.CurrentDomain.BaseDirectory; #endif return base.ParseOptions(args, runtimeSetup, languageSetup); }
protected virtual ConsoleOptions ParseOptions(string /*!*/[] /*!*/ args, ScriptRuntimeSetup /*!*/ runtimeSetup, LanguageSetup /*!*/ languageSetup) { var languageOptionsParser = CreateOptionsParser(); try { languageOptionsParser.Parse(args, runtimeSetup, languageSetup, PlatformAdaptationLayer); } catch (InvalidOptionException e) { ReportInvalidOption(e); return(null); } return(languageOptionsParser.CommonConsoleOptions); }
private static void SetIronRubyLibraryPaths(LanguageSetup languageSetup, IList<string> libraryPaths) { languageSetup.Options["LibraryPaths"] = string.Join(";", GenericCollectionUtils.ToArray(libraryPaths)); }
public virtual int Run(string[] args) { var runtimeSetup = CreateRuntimeSetup(); var options = new ConsoleHostOptions(); _optionsParser = new ConsoleHostOptionsParser(options, runtimeSetup); try { ParseHostOptions(args); } catch (InvalidOptionException e) { Console.Error.WriteLine("Invalid argument: " + e.Message); return _exitCode = 1; } SetEnvironment(); string provider = GetLanguageProvider(runtimeSetup); LanguageSetup languageSetup = null; foreach (var language in runtimeSetup.LanguageSetups) { if (language.TypeName == provider) { languageSetup = language; } } if (languageSetup == null) { // the language doesn't have a setup -> create a default one: languageSetup = new LanguageSetup(Provider.AssemblyQualifiedName, Provider.Name); runtimeSetup.LanguageSetups.Add(languageSetup); } // inserts search paths for all languages (/paths option): InsertSearchPaths(runtimeSetup.Options, Options.SourceUnitSearchPaths); _consoleOptions = ParseOptions(Options.IgnoredArgs.ToArray(), runtimeSetup, languageSetup); if (_consoleOptions == null) { return _exitCode = 1; } _runtime = new ScriptRuntime(runtimeSetup); try { _engine = _runtime.GetEngineByTypeName(provider); } catch (Exception e) { Console.Error.WriteLine(e.Message); return _exitCode = 1; } Execute(); return _exitCode; }
public RubyCatalog(RubyPartSource source) { if (source == null) throw new ArgumentNullException("source"); _ruby = Ruby.CreateEngine(); var rubySetup = new LanguageSetup(typeof(RubyContext).AssemblyQualifiedName); rubySetup.FileExtensions.Add("rb"); rubySetup.Names.Add("IronRuby"); var setup = new ScriptRuntimeSetup(); setup.LanguageSetups.Add(rubySetup); _ruby.Runtime.LoadAssembly(typeof(RubyPartDefinition).Assembly); _ruby.Runtime.LoadAssembly(typeof(ExportDefinition).Assembly); _ruby.Runtime.LoadAssembly(typeof(IEnumerable<int>).Assembly); var parts = new Hashtable(); _ruby.Runtime.Globals.SetVariable("MefPartsCollection", parts); // _ruby.Execute(PartDefinition); // Script.PartDefinition); _ruby.Execute(Script.PartDefinition); source.Execute(_ruby); _parts = parts.Values.Cast<ComposablePartDefinition>().AsQueryable(); }
internal static LanguageSetup CreateLanguageSetup() { var setup = new LanguageSetup( typeof(MyContext).AssemblyQualifiedName, "test", new[] { "test" }, new[] { ".tst" }); return setup; }
/// <summary> /// Configures the IronRuby language options. /// </summary> /// <remarks> /// <para> /// The default implementation does nothing. Subclasses may override to /// configure the IronRuby language options. /// </para> /// </remarks> /// <param name="languageSetup">The IronRuby language setup.</param> /// <param name="libraryPaths">The list of IronRuby library paths.</param> protected virtual void ConfigureIronRuby(LanguageSetup languageSetup, IList<string> libraryPaths) { }
public override void Reset(ScriptScope scope) { var setup = new ScriptRuntimeSetup(); var ls = new LanguageSetup(typeof(PythonContext).AssemblyQualifiedName, "Python", new[] { "py" }, new[] { ".py" }); setup.LanguageSetups.Add(ls); var runtime = new ScriptRuntime(setup); _engine = runtime.GetEngine("py"); _scope = scope == null ? _engine.Runtime.CreateScope() : scope; }
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); }
protected override void ConfigureIronRuby(LanguageSetup languageSetup, IList<string> libraryPaths) { libraryPaths.Add(Path.GetFullPath(@"..\Scripts\IronRuby")); }
private static IList<string> GetIronRubyLibraryPaths(LanguageSetup languageSetup) { List<string> libraryPaths = new List<string>(); object value; if (languageSetup.Options.TryGetValue("LibraryPaths", out value)) { libraryPaths.AddRange(((string)value).Split(';')); } return libraryPaths; }
protected override ConsoleOptions ParseOptions(string[] args, ScriptRuntimeSetup runtimeSetup, LanguageSetup languageSetup) { var options = base.ParseOptions(args, runtimeSetup, languageSetup); _pyoptions = (PythonConsoleOptions)options; return(options); }
public void RubyLanguageIsSetup() { LanguageSetup setup = host.CallCreateLanguageSetup(); Assert.AreEqual("IronRuby", setup.DisplayName); }
private void Initialize() { if (!IsInitialized && !IsInitializing) { lock (_sync) { if (!IsInitialized && !IsInitializing) { IsInitializing = true; var setup = new ScriptRuntimeSetup(); var languageSetup = new LanguageSetup( "IronRuby.Runtime.RubyContext, IronRuby, Version=1.0.0.1, Culture=neutral, PublicKeyToken=baeaf26a6e0611a7", IronConstant.IronRubyLanguageName, new[] { "IronRuby", "Ruby", "rb" }, new[] { ".rb" }); setup.LanguageSetups.Add(languageSetup); setup.HostType = typeof(IronHive); setup.DebugMode = IronConstant.IronEnv == IronEnvironment.Debug; _scriptRuntime = new ScriptRuntime(setup); (_scriptRuntime.Host as IronHive).Id = _hiveId; _scriptRuntime.LoadAssembly(typeof(IronRuntime).Assembly); // IronSharePoint _scriptRuntime.LoadAssembly(typeof(SPSite).Assembly); // Microsoft.SharePoint _scriptRuntime.LoadAssembly(typeof(IHttpHandler).Assembly); // System.Web using (new SPMonitoredScope("Creating IronEngine(s)")) { string ironRubyRoot = Path.Combine(IronHive.FeatureFolderPath, "IronSP_IronRuby10\\"); SPSecurity.RunWithElevatedPrivileges(() => PrivilegedInitialize(ironRubyRoot)); ScriptEngine rubyEngine = _scriptRuntime.GetEngineByFileExtension(".rb"); rubyEngine.SetSearchPaths(new List <String> { Path.Combine(ironRubyRoot, @"Lib\IronRuby"), Path.Combine(ironRubyRoot, @"Lib\ruby\site_ruby\1.8"), Path.Combine(ironRubyRoot, @"Lib\ruby\1.8"), IronHive.CurrentDir }); var ironRubyEngine = new IronEngine(this, rubyEngine); Engines[".rb"] = ironRubyEngine; ScriptScope scope = rubyEngine.CreateScope(); scope.SetVariable("iron_runtime", this); scope.SetVariable("ruby_engine", ironRubyEngine); scope.SetVariable("rails_root", IronHive.CurrentDir); scope.SetVariable("rails_env", IronConstant.IronEnv == IronEnvironment.Debug ? "development" : IronConstant.IronEnv.ToString().ToLower()); rubyEngine.Execute("$RUNTIME = iron_runtime; $RUBY_ENGINE = ruby_engine; RAILS_ROOT = rails_root; RAILS_ENV = rails_env", scope); IronConsole.Execute(@" Dir.chdir RAILS_ROOT require 'rubygems' begin load_assembly 'Microsoft.SharePoint.Publishing, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c' require './iron_sharepoint' require 'application' rescue Exception => ex IRON_DEFAULT_LOGGER.error ex ensure $RUBY_ENGINE.is_initialized = true end", ".rb", false); IsInitializing = false; IsInitialized = true; } } } } }
public override void Reset(ScriptScope scope) { var setup = new ScriptRuntimeSetup(); var py = new LanguageSetup(typeof(PythonContext).AssemblyQualifiedName, "Python", new[] { "py" }, new[] { ".py" }); var rb = new LanguageSetup(typeof(RubyContext).AssemblyQualifiedName, "Ruby", new[] { "rb" }, new[] { ".rb" }); rb.Options["InterpretedMode"] = true; rb.Options["SearchPaths"] = new[] { MerlinPath + @"\libs", BasePath + @"\ruby\site_ruby\1.8", BasePath + @"\ruby\site_ruby", BasePath + @"\ruby\1.8" }; setup.LanguageSetups.Add(py); setup.LanguageSetups.Add(rb); var runtime = new ScriptRuntime(setup); _engine = runtime.GetEngine("rb"); _scope = scope == null ? _engine.Runtime.CreateScope() : scope; _topLevelBinding = (IronRuby.Builtins.Binding)_engine.Execute("binding", _scope); }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { System.Windows.Forms.Button m_btnCancel; System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(LanguageSelectionDlg)); System.Windows.Forms.Button m_btnHelp; this.m_languageSetup = new SIL.FieldWorks.Common.Controls.LanguageSetup(); this.m_btnOK = new System.Windows.Forms.Button(); this.m_helpProvider = new System.Windows.Forms.HelpProvider(); m_btnCancel = new System.Windows.Forms.Button(); m_btnHelp = new System.Windows.Forms.Button(); this.SuspendLayout(); // // m_btnCancel // m_btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; resources.ApplyResources(m_btnCancel, "m_btnCancel"); m_btnCancel.Name = "m_btnCancel"; this.m_helpProvider.SetShowHelp(m_btnCancel, ((bool)(resources.GetObject("m_btnCancel.ShowHelp")))); // // m_btnHelp // this.m_helpProvider.SetHelpString(m_btnHelp, resources.GetString("m_btnHelp.HelpString")); resources.ApplyResources(m_btnHelp, "m_btnHelp"); m_btnHelp.Name = "m_btnHelp"; this.m_helpProvider.SetShowHelp(m_btnHelp, ((bool)(resources.GetObject("m_btnHelp.ShowHelp")))); m_btnHelp.Click += new System.EventHandler(this.m_btnHelp_Click); // // m_languageSetup // this.m_languageSetup.EthnologueCode = global::SIL.FieldWorks.FwCoreDlgs.FwCoreDlgs.kstidOpen; this.m_languageSetup.LanguageName = ""; resources.ApplyResources(this.m_languageSetup, "m_languageSetup"); this.m_languageSetup.Name = "m_languageSetup"; this.m_helpProvider.SetShowHelp(this.m_languageSetup, ((bool)(resources.GetObject("m_languageSetup.ShowHelp")))); this.m_languageSetup.StartedInModifyState = false; this.m_languageSetup.LanguageNameChanged += new System.EventHandler(this.m_languageSetup_LanguageNameChanged); // // m_btnOK // this.m_btnOK.DialogResult = System.Windows.Forms.DialogResult.OK; resources.ApplyResources(this.m_btnOK, "m_btnOK"); this.m_btnOK.Name = "m_btnOK"; this.m_helpProvider.SetShowHelp(this.m_btnOK, ((bool)(resources.GetObject("m_btnOK.ShowHelp")))); // // LanguageSelectionDlg // this.AcceptButton = this.m_btnOK; resources.ApplyResources(this, "$this"); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.CancelButton = m_btnCancel; this.Controls.Add(m_btnHelp); this.Controls.Add(this.m_btnOK); this.Controls.Add(m_btnCancel); this.Controls.Add(this.m_languageSetup); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; this.MaximizeBox = false; this.MinimizeBox = false; this.Name = "LanguageSelectionDlg"; this.m_helpProvider.SetShowHelp(this, ((bool)(resources.GetObject("$this.ShowHelp")))); this.ShowInTaskbar = false; this.ResumeLayout(false); }
public virtual int Run(string[] args) { var runtimeSetup = CreateRuntimeSetup(); var options = new ConsoleHostOptions(); _optionsParser = new ConsoleHostOptionsParser(options, runtimeSetup); try { ParseHostOptions(args); } catch (InvalidOptionException e) { Console.Error.WriteLine("Invalid argument: " + e.Message); return _exitCode = 1; } SetEnvironment(); string provider = GetLanguageProvider(runtimeSetup); LanguageSetup languageSetup = null; foreach (var language in runtimeSetup.LanguageSetups) { if (language.TypeName == provider) { languageSetup = language; } } if (languageSetup == null) { // the language doesn't have a setup -> create a default one: languageSetup = new LanguageSetup(Provider.AssemblyQualifiedName, Provider.Name); runtimeSetup.LanguageSetups.Add(languageSetup); } // inserts search paths for all languages (/paths option): InsertSearchPaths(runtimeSetup.Options, Options.SourceUnitSearchPaths); _languageOptionsParser = CreateOptionsParser(); try { _languageOptionsParser.Parse(Options.IgnoredArgs.ToArray(), runtimeSetup, languageSetup, PlatformAdaptationLayer); } catch (InvalidOptionException e) { Console.Error.WriteLine(e.Message); return _exitCode = -1; } #if !SILVERLIGHT if (typeof(DynamicMethod).GetConstructor(new Type[] { typeof(string), typeof(Type), typeof(Type[]), typeof(bool) }) == null) { Console.WriteLine(string.Format("{0} requires .NET 2.0 SP1 or later to run.", languageSetup.DisplayName)); Environment.Exit(1); } #endif _runtime = new ScriptRuntime(runtimeSetup); try { _engine = _runtime.GetEngineByTypeName(provider); } catch (Exception e) { Console.Error.WriteLine(e.Message); return _exitCode = 1; } Execute(); return _exitCode; }
protected virtual ConsoleOptions ParseOptions(string/*!*/[]/*!*/ args, ScriptRuntimeSetup/*!*/ runtimeSetup, LanguageSetup/*!*/ languageSetup) { var languageOptionsParser = CreateOptionsParser(); try { languageOptionsParser.Parse(args, runtimeSetup, languageSetup, PlatformAdaptationLayer); } catch (InvalidOptionException e) { ReportInvalidOption(e); return null; } return languageOptionsParser.CommonConsoleOptions; }
public LanguageSetup[] GetLanguageSetups() { int intNumLanguages = 0; if (ConfigurationManager.AppSettings["LanguageCount"] != "") { try { intNumLanguages = Convert.ToInt32(ConfigurationManager.AppSettings["LanguageCount"]); } catch { intNumLanguages = 0; } } List<LanguageSetup> lLanguageSetups = new List<LanguageSetup>(); for (int i = 0; i < intNumLanguages; i++) { string strLanguageSetup = ConfigurationManager.AppSettings["Language" + ((int)(i + 1)).ToString()]; if (strLanguageSetup != "") { string[] saLanguageSetup = strLanguageSetup.Split(new char[] { ';' }); if (saLanguageSetup.Length == 4) { LanguageSetup objLanguageSetup = new LanguageSetup(); lLanguageSetups.Add(objLanguageSetup); objLanguageSetup.LanguageText = saLanguageSetup[0]; objLanguageSetup.Culture = saLanguageSetup[1]; objLanguageSetup.UICulture = saLanguageSetup[2]; objLanguageSetup.ImageURL = saLanguageSetup[3]; } } } return lLanguageSetups.ToArray(); }
public virtual int Run(string[] args) { var runtimeSetup = CreateRuntimeSetup(); var options = new ConsoleHostOptions(); _optionsParser = new ConsoleHostOptionsParser(options, runtimeSetup); try { ParseHostOptions(args); } catch (InvalidOptionException e) { Console.Error.WriteLine("Invalid argument: " + e.Message); return(_exitCode = 1); } SetEnvironment(); string provider = GetLanguageProvider(runtimeSetup); LanguageSetup languageSetup = null; foreach (var language in runtimeSetup.LanguageSetups) { if (language.TypeName == provider) { languageSetup = language; } } if (languageSetup == null) { // the language doesn't have a setup -> create a default one: languageSetup = new LanguageSetup(Provider.AssemblyQualifiedName, Provider.Name); runtimeSetup.LanguageSetups.Add(languageSetup); } // inserts search paths for all languages (/paths option): InsertSearchPaths(runtimeSetup.Options, Options.SourceUnitSearchPaths); _languageOptionsParser = CreateOptionsParser(); try { _languageOptionsParser.Parse(Options.IgnoredArgs.ToArray(), runtimeSetup, languageSetup, PlatformAdaptationLayer); } catch (InvalidOptionException e) { Console.Error.WriteLine(e.Message); return(_exitCode = -1); } #if !SILVERLIGHT if (typeof(DynamicMethod).GetConstructor(new Type[] { typeof(string), typeof(Type), typeof(Type[]), typeof(bool) }) == null) { Console.WriteLine(string.Format("{0} requires .NET 2.0 SP1 or later to run.", languageSetup.DisplayName)); Environment.Exit(1); } #endif _runtime = new ScriptRuntime(runtimeSetup); try { _engine = _runtime.GetEngineByTypeName(provider); } catch (Exception e) { Console.Error.WriteLine(e.Message); return(_exitCode = 1); } Execute(); return(_exitCode); }
/* <configSections> * <section name="microsoft.scripting" type="Microsoft.Scripting.Hosting.Configuration.Section, Microsoft.Scripting, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" requirePermission="false" /> * </configSections> * * <microsoft.scripting> * <languages> * <language names="IronPython;Python;py" extensions=".py" displayName="IronPython 2.7.1" type="IronPython.Runtime.PythonContext, IronPython, Version=2.7.1.0, Culture=neutral, PublicKeyToken=null" /> * <language names="IronRuby;Ruby;rb" extensions=".rb" displayName="IronRuby" type="IronRuby.Runtime.RubyContext, IronRuby, Version=0.9.5.0, Culture=neutral, PublicKeyToken=null" /> * </languages> * * <options> * <set language="Ruby" option="LibraryPaths" value="..\..\Languages\Ruby\libs\;..\..\..\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\ruby\site_ruby\1.8\;..\..\..\External.LCA_RESTRICTED\Languages\Ruby\redist-libs\ruby\1.8\" /> * </options> * </microsoft.scripting>*/ internal Host(LanguageSetup language, string languageName) : this(language, languageName, true) { }