private GetEngine ( LanguageContext language ) : ScriptEngine | ||
language | LanguageContext | |
return | ScriptEngine |
static void Main(string[] args) { try { ScriptRuntimeSetup setup = ScriptRuntimeSetup.ReadConfiguration(); ScriptRuntime runtime = new ScriptRuntime(setup); runtime.GetEngine("Python").Execute("print \"Hello, Hosted Script World!\""); //runtime.ExecuteFile(PYTHON_FILE); //ScriptScope scope = runtime.GetEngine("Python").CreateScope(); //scope.SetVariable("name", "John Zablocki"); #region func //Func<string, string> reverse = (s) => { // string reversed = ""; // for (int i = s.Length - 1; i >= 0; i--) { // reversed += s[i]; // } // return reversed; // }; //scope.SetVariable("reverse", reverse); #endregion //runtime.GetEngine("Python").ExecuteFile(PYTHON_FILE, scope); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
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); } }
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 HAPITestBase() { var ses = CreateSetup(); ses.HostType = typeof(TestHost); _runtime = new ScriptRuntime(ses); _remoteRuntime = ScriptRuntime.CreateRemote(TestHelpers.CreateAppDomain("Alternate"), ses); _runTime = _runtime;// _remoteRuntime; _PYEng = _runTime.GetEngine("py"); _RBEng = _runTime.GetEngine("rb"); SetTestLanguage(); _defaultScope = _runTime.CreateScope(); _codeSnippets = new PreDefinedCodeSnippets(); }
public static Action<HappyRuntimeContext> CompileModule(string filename) { ScriptRuntime runtime = new ScriptRuntime(ScriptRuntimeSetup.ReadConfiguration()); Microsoft.Scripting.Hosting.ScriptEngine engine = runtime.GetEngine("ht"); ScriptScope globals = engine.CreateScope(); var scriptSource = engine.CreateScriptSourceFromString(readFile(filename), filename, SourceCodeKind.File); return scriptSource.Execute(globals); }
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); }
public void ReadConfiguration_1Lang() { string configFile = GetTempConfigFile(new[]{LangSetup.Python}); var srs = ScriptRuntimeSetup.ReadConfiguration(configFile); Assert.AreEqual(1, srs.LanguageSetups.Count); var sr = new ScriptRuntime(srs); Assert.AreEqual(1, sr.Setup.LanguageSetups.Count); var pythonEngine = sr.GetEngine("py"); Assert.IsTrue(pythonEngine.IsValidPythonEngine()); }
/// <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(); }
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); }
public void Configuration_MutateAndCheck3() { string configFile = GetTempConfigFile(new[] { LangSetup.Python }); var sr = new ScriptRuntime(ScriptRuntimeSetup.ReadConfiguration(configFile)); var eng = sr.GetEngine("py"); var config = eng.Setup; config = null; Assert.IsNotNull(eng.Setup); }
public void ReadConfiguration_All4Langs() { var srs = ScriptRuntimeSetup.ReadConfiguration(TestHelpers.StandardConfigFile); Assert.AreEqual(2, srs.LanguageSetups.Count); var runtime = new ScriptRuntime(srs); foreach (var lang in srs.LanguageSetups) { Assert.IsTrue((lang.Names != null) && (lang.Names.Count != 0)); //ensure this doesn't throw var engine = runtime.GetEngine(lang.Names[0]); Assert.AreEqual(lang.DisplayName, engine.Setup.DisplayName); } }
public Scripting() { Host = Python.CreateRuntime(); Scope = Host.CreateScope(); Engine = Host.GetEngine("Python"); PacketHooks = new Dictionary<NSCommand, List<PacketHookCall>>(); UpdateHooks = new List<UpdateHookCall>(); ChatHooks = new List<ChatHookCall>(); ChatCommandHooks = new Dictionary<string, List<ChatCommandHookCall>>(); NameFormatHooks = new List<NameFormatHookCall>(); PlayerXPHooks = new List<PlayerXPHookCall>(); }
public object GetObject(string objectName) { Dictionary<string, object> instances = new Dictionary<string, object>(); ScriptRuntimeSetup setup = ScriptRuntimeSetup.ReadConfiguration(); ScriptRuntime runtime = new ScriptRuntime(setup); runtime.LoadAssembly(Assembly.GetExecutingAssembly()); ScriptEngine engine = runtime.GetEngine("IronPython"); runtime.Globals.SetVariable("instances", instances); engine.ExecuteFile("Objects.py", runtime.Globals); return instances[objectName]; }
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(); }
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+"); }
/// <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 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"); }
static void Main(string[] args) { var runtimeSetup = Python.CreateRuntimeSetup(new Dictionary<string, object>()); runtimeSetup.DebugMode = true; var runtime = new ScriptRuntime(runtimeSetup); var scope = runtime.CreateScope(new Dictionary<string, object> { { "name" , "Batman" } }); var engine = runtime.GetEngine("py"); var scriptSource = engine.CreateScriptSourceFromFile("script.py"); var compiledCode = scriptSource.Compile(); compiledCode.Execute(scope); }
public IronRubySupport(bool debug) { this.debug = debug; ScriptRuntimeSetup runtimeSetup = new ScriptRuntimeSetup(); LanguageSetup rubySetup = Ruby.CreateRubySetup(); if (debug) { runtimeSetup.DebugMode = true; rubySetup.ExceptionDetail = true; } runtimeSetup.LanguageSetups.Add(rubySetup); runtime = new ScriptRuntime(runtimeSetup); // can in theory be kept around rubyEngine = runtime.GetEngine("ruby"); // so can this }
public void SetUp() { var configFile = Path.GetFullPath(Uri.UnescapeDataString(new Uri(typeof(TestFixtureBase).Assembly.CodeBase).AbsolutePath)) + ".config"; Runtime = new ScriptRuntime(ScriptRuntimeSetup.ReadConfiguration(configFile)); _output = new MemoryStream(); _errorOutput = new MemoryStream(); Runtime.IO.SetOutput(_output, Encoding.ASCII); Runtime.IO.SetErrorOutput(_errorOutput, Encoding.ASCII); Engine = Runtime.GetEngine("ht"); LanguageContext = HostingHelpers.GetLanguageContext(Engine) as HappyLanguageContext; GlobalScope = Engine.CreateScope(); Assert.IsNotNull(GlobalScope); }
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) { try { ScriptRuntimeSetup setup = ScriptRuntimeSetup.ReadConfiguration(); ScriptRuntime runtime = new ScriptRuntime(setup); ScriptEngine engine = runtime.GetEngine("Python"); ScriptScope scope = engine.CreateScope(); engine.ExecuteFile("Scripts\\BuildProject.py", scope); IronPython.Runtime.py var constructor = scope.GetVariable("__init__"); Console.WriteLine(constructor); } catch (Exception ex) { Console.WriteLine(ex.GetBaseException().Message); } }
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); } }
private void PluginEditor_Load(object sender, EventArgs e) { Open = true; PluginEditorTE.ShowTabs = false; PluginEditorTE.ShowEOLMarkers = false; PluginEditorTE.ShowSpaces = false; PluginEditorTE.ShowInvalidLines = false; PluginEditorTE.TabIndent = 2; Directory.SetCurrentDirectory(Config.RootDir); HighlightingManager.Manager.AddSyntaxModeFileProvider(new EditorSyntaxModesProvider()); PluginEditorTE.SetHighlighting("Python"); ScriptRuntimeSetup Setup = new ScriptRuntimeSetup(); Setup.LanguageSetups.Add(IronRuby.Ruby.CreateRubySetup()); Setup.LanguageSetups.Add(IronPython.Hosting.Python.CreateLanguageSetup(null)); RunTime = new ScriptRuntime(Setup); Engine = RunTime.GetEngine("py"); APIDoc.BuildPluginEditorTrees(); PluginEditorTE.ActiveTextAreaControl.TextArea.KeyUp += new System.Windows.Forms.KeyEventHandler(this.PluginEditorTE_KeyUp); PluginEditorTE.Document.DocumentChanged += new DocumentEventHandler(this.PluginEditorTE_Change); }
public FunctionsTests() { _env = Totem.CreateRuntime(); _te = _env.GetEngine("totem"); }
static ScriptEngine GetScriptEngine() { ScriptRuntimeSetup Setup = new ScriptRuntimeSetup(); Setup.LanguageSetups.Add(IronRuby.Ruby.CreateRubySetup()); Setup.LanguageSetups.Add(IronPython.Hosting.Python.CreateLanguageSetup(null)); ScriptRuntime RunTime = new ScriptRuntime(Setup); ScriptEngine Engine = RunTime.GetEngine("py"); ScriptScope Scope = RunTime.CreateScope(); Assembly MainAssembly = Assembly.GetExecutingAssembly(); string RootDir = Directory.GetParent(MainAssembly.Location).FullName; RunTime.LoadAssembly(MainAssembly); RunTime.LoadAssembly(typeof(String).Assembly); RunTime.LoadAssembly(typeof(Uri).Assembly); RunTime.LoadAssembly(typeof(XmlDocument).Assembly); Engine.Runtime.TryGetEngine("py", out Engine); return Engine; }
internal static void InitialiseScriptingEnvironment() { ScriptRuntimeSetup Setup = new ScriptRuntimeSetup(); Setup.LanguageSetups.Add(IronRuby.Ruby.CreateRubySetup()); Setup.LanguageSetups.Add(IronPython.Hosting.Python.CreateLanguageSetup(null)); RunTime = new ScriptRuntime(Setup); Engine = RunTime.GetEngine("py"); Scope = RunTime.CreateScope(); RunTime.IO.SetOutput(ShellOutStream, Encoding.UTF8); RunTime.IO.SetErrorOutput(ShellOutStream, Encoding.UTF8); Assembly MainAssembly = Assembly.GetExecutingAssembly(); string RootDir = Directory.GetParent(MainAssembly.Location).FullName; string HAGPath = Path.Combine(RootDir, "HtmlAgilityPack.dll"); Assembly HAGAssembly = Assembly.LoadFile(HAGPath); RunTime.LoadAssembly(MainAssembly); RunTime.LoadAssembly(HAGAssembly); RunTime.LoadAssembly(typeof(String).Assembly); RunTime.LoadAssembly(typeof(Uri).Assembly); RunTime.LoadAssembly(typeof(XmlDocument).Assembly); Engine.Runtime.TryGetEngine("py", out Engine); List<string> PySearchPaths = new List<string>(); foreach (string PyPath in PyPaths) { PySearchPaths.Add(PyPath.Replace("$ROOTDIR", RootDir)); } try { Engine.SetSearchPaths(PySearchPaths); } catch(Exception Exp) { IronException.Report("Unable to set PyPaths", Exp.Message, Exp.StackTrace); } foreach (string PyCommand in PyCommands) { try { ExecuteStartUpCommand(PyCommand); } catch(Exception Exp) { IronException.Report("Unable to execute Python startup command - " + PyCommand, Exp.Message, Exp.StackTrace); } } Engine.Runtime.TryGetEngine("rb", out Engine); List<string> RbSearchPaths = new List<string>(); foreach (string RbPath in RbPaths) { RbSearchPaths.Add(RbPath.Replace("$ROOTDIR", RootDir)); } Engine.SetSearchPaths(RbSearchPaths); foreach (string RbCommand in RbCommands) { try { ExecuteStartUpCommand(RbCommand); } catch (Exception Exp) { IronException.Report("Unable to execute Ruby startup command" + RbCommand, Exp.Message, Exp.StackTrace); } } Engine.Runtime.TryGetEngine("py", out Engine); ExecuteStartUpCommand("print 123"); ShellOutText = new StringBuilder(); IronUI.ResetInteractiveShellResult(); }
static IronRubyScript() { runtime = IronRuby.Ruby.CreateRuntime(); _rubyEngine = runtime.GetEngine("Ruby"); _scope = _rubyEngine.CreateScope(); }
private void ExecuteLabel_MouseUp(object sender, MouseButtonEventArgs e) { string code = this.codeBox.Text; ScriptRuntimeSetup setup = new ScriptRuntimeSetup(); setup.LanguageSetups.Add(AplusCore.Runtime.AplusLanguageContext.LanguageSetup); setup.Options.Add( new KeyValuePair<string, object>( "LexerMode", this.aplinput ? AplusCore.Compiler.LexerMode.APL : AplusCore.Compiler.LexerMode.ASCII ) ); ScriptRuntime dlrRuntime = new ScriptRuntime(setup); ScriptEngine engine = dlrRuntime.GetEngine(@"A+"); try { AType result = engine.Execute<AType>(code); this.ResultTextBox.Text = result.ToString(); } catch (Error error) { this.ResultTextBox.Text = error.ToString(); } catch (Exception ex) { this.ResultTextBox.Text = ex.Message; } if (!this.AnimatedExpander.IsExpanded) { this.AnimatedExpander.IsExpanded = true; ExpandOrCollapese(this.AnimatedExpander); } }
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; }