void FreePython() { prGetNProps = null; prFindProp = null; prGetPropName = null; prGetPropVal = null; prSetPropVal = null; prIsPropReadable = null; prIsPropWritable = null; prGetNMethods = null; prFindMethod = null; prGetMethodName = null; prGetNParams = null; prGetParamDefValue = null; prHasRetVal = null; prCallAsProc = null; prCallAsFunc = null; prCleanAll = null; prAddReferences = null; prClearExcInfo = null; ops = null; conn_scope = null; interf_scope = null; interactor = null; sruntime.Shutdown(); }
private static string[] GetScriptInfo(string path, int t) { ScriptEngine engine; ScriptRuntime runtime = null; try { engine = Python.CreateEngine(); var pc = HostingHelpers.GetLanguageContext(engine) as PythonContext; var hooks = pc.SystemState.Get__dict__()["path_hooks"] as List; hooks.Clear(); ScriptSource source = engine.CreateScriptSourceFromFile(path); CompiledCode code = source.Compile(); ScriptScope scope = engine.CreateScope(); runtime = engine.Runtime; Assembly assembly = typeof(Program).Assembly; runtime.LoadAssembly(Assembly.LoadFile(assembly.Location)); source.Execute(scope); dynamic pyClass = scope.GetVariable("Mml2vgmScript"); dynamic mml2vgmScript = pyClass(); switch (t) { case 0: return(mml2vgmScript.title().Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries)); case 1: return(mml2vgmScript.scriptType().Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries)); case 2: return(mml2vgmScript.supportFileExt().Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries)); case 3: string ret = mml2vgmScript.defaultShortCutKey(); if (!string.IsNullOrEmpty(ret)) { return(ret.Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries)); } break; } } catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException) { ;//無視 } catch (Exception ex) { log.ForcedWrite(ex); } finally { if (runtime != null) { runtime.Shutdown(); } GC.Collect(); } return(new string[] { "" });// Path.GetFileName(path); }
private void UpdateScript(string script) { LogTo.Debug("A script was changed - {0}", script); if (File.Exists(script)) { _runtime.Shutdown(); _runtime = Python.CreateRuntime(); try { _script = _runtime.UseFile(script); LogTo.Info("Script loaded"); ScriptScope scope = _script; dynamic parser = scope.GetVariable("ParserScript"); name = parser.Name; version = parser.Version; author = parser.Author; LogTo.Info("Name: {0}, Version: {1}, Author: {2}", name, version, author); } catch (SyntaxErrorException e) { LogTo.ErrorException("Syntax error", e); } catch (Exception e) { LogTo.WarnException("Script error", e); } } else { LogTo.Error("Script not loaded (file doesn't exist)"); } }
public void ExecuteScript() { ReleaseAnyVariable(); if (engine == null) { engine = UnityPython.CreateEngine(); } runtime = engine.Runtime; scope = runtime.CreateScope(); scripts.ForEach(script => { var scriptContent = script.GetScriptHeader(); scriptContent += script.script; // create script source from content var source = engine.CreateScriptSourceFromString(scriptContent); try { // execute python script source.Execute(scope); } catch (System.Exception exc) { Debug.LogError(exc); } }); runtime.Shutdown(); this.stoppable = false; }
public void run() { if (HelpRequested || errors.Count > 0) { foreach (var error in errors) { Console.WriteLine(error); } provideHelp(); return; } ScriptRuntime scriptRuntime = null; try { // ScriptRuntime scriptRuntime = ScriptRuntime.CreateFromConfiguration(); // This is the "standard" way to do it; but it's rather less flexible. scriptRuntime = EssenceLaunchPad.CreateRuntime(optionsBuilder); ScriptEngine engine = scriptRuntime.GetEngine("Essence#"); foreach (var executive in executives) { executive.run(engine); } } finally { if (scriptRuntime != null) { scriptRuntime.Shutdown(); } } }
public void ExecuteScript() { // release any variable ReleaseAnyVariable(); runtime = engine.Runtime; scope = runtime.CreateScope(); var scriptContent = GetScriptHeader(); scriptContent += script; // create script source from content var source = engine.CreateScriptSourceFromString(scriptContent); // include unity variables IncludeVariables(); // updated unity variables UpdateUnityVariables(); // include python variables IncludePythonVariables(); try { // execute python script source.Execute(scope); // store python variables StorePythonVariables(); } catch (System.Exception exc) { Debug.LogError(exc); } runtime.Shutdown(); this.stoppable = false; }
private void Shutdown() { if (_scriptRuntime != null) { if (BeforeUnload != null) { // アンロード時に出るExceptionはとりあえず全部握りつぶす foreach (EventHandler handler in BeforeUnload.GetInvocationList()) { try { handler.Invoke(this, EventArgs.Empty); } catch (Exception e) { CurrentSession.Logger.Error("Exception at BeforeUnload(Ignore): " + e.Message); } } } _scriptRuntime.Shutdown(); _scriptRuntime = null; BeforeUnload = null; _sessionProxy.RemoveAllEvents(); _serverProxy.RemoveAllEvents(); } }
public void SetStoppable(bool stoppable) { this.stoppable = stoppable; if (stoppable) { if (!runtime.IsNull()) { runtime.Shutdown(); } } }
static void Main(string[] args) { TimeSpan durationToRun = TimeSpan.Zero; ScriptRuntime scriptRuntime = null; try { // ScriptRuntime scriptRuntime = ScriptRuntime.CreateFromConfiguration(); // This is the "standard" to do it; but it's rather less flexible. var optionsBuilder = new EssenceSharpOptionsBuilder(); optionsBuilder.addScriptSearchPath("."); String scriptFileName = "Default.es"; if (args.Length > 0) { scriptFileName = args[0]; var extension = Path.GetExtension(scriptFileName); if (extension != ".es") { scriptFileName = scriptFileName + ".es"; } for (var i = 1; i < args.Length; i++) { optionsBuilder.loadLibrary(args[i]); } } scriptRuntime = EssenceLaunchPad.CreateRuntime(optionsBuilder); ScriptEngine engine = scriptRuntime.GetEngine("Essence#"); var compilationOptions = (ESCompilerOptions)engine.GetCompilerOptions(); compilationOptions.EnvironmentName = "Smalltalk"; // Should eventually be specifiable by command-line argument. ScriptSource script = engine.CreateScriptSourceFromPathSuffix(scriptFileName); var scriptArgs = new Object[] {}; // Should eventually be specifiable by command-line argument(s). var stopwatch = new Stopwatch(); stopwatch.Start(); var value = script.Execute(compilationOptions, scriptArgs); stopwatch.Stop(); durationToRun = stopwatch.Elapsed; Console.WriteLine(" => " + value); } finally { if (scriptRuntime != null) { scriptRuntime.Shutdown(); } Console.WriteLine("________________________________________"); Console.WriteLine("Script run time = " + durationToRun.ToString() + " (includes setup and compilation time)"); } }
private static void ExploreOrRun(TestPackage testPackage, ScriptRuntimeSetup scriptRuntimeSetup, string testDriverScriptPath, TestExplorationOptions testExplorationOptions, TestExecutionOptions testExecutionOptions, IMessageSink messageSink, IProgressMonitor progressMonitor, ILogger logger) { using (BufferedLogWriter outputWriter = new BufferedLogWriter(logger, LogSeverity.Info, Encoding.Default), errorWriter = new BufferedLogWriter(logger, LogSeverity.Error, Encoding.Default)) { using (var queuedMessageSink = new QueuedMessageSink(messageSink)) { using (new ConsoleRedirection(outputWriter, errorWriter)) { var scriptRuntime = new ScriptRuntime(scriptRuntimeSetup); scriptRuntime.IO.SetInput(Stream.Null, TextReader.Null, Encoding.Default); scriptRuntime.IO.SetOutput(new TextWriterStream(outputWriter), outputWriter); scriptRuntime.IO.SetErrorOutput(new TextWriterStream(errorWriter), errorWriter); try { var scriptParameters = new Dictionary <string, object>(); scriptParameters.Add("Verb", testExecutionOptions != null ? "Run" : "Explore"); scriptParameters.Add("TestPackage", testPackage); scriptParameters.Add("TestExplorationOptions", testExplorationOptions); scriptParameters.Add("TestExecutionOptions", testExecutionOptions); scriptParameters.Add("MessageSink", queuedMessageSink); scriptParameters.Add("ProgressMonitor", progressMonitor); scriptParameters.Add("Logger", logger); scriptRuntime.Globals.SetVariable(ScriptParametersVariableName, scriptParameters); RunScript(scriptRuntime, testDriverScriptPath); } finally { scriptRuntime.Shutdown(); } } } } }
public void run(bool withLeak) { //set up script environment Dictionary <String, Object> options = new Dictionary <string, object>(); options["LightweightScopes"] = true; ScriptEngine engine = Python.CreateEngine(options); PythonCompilerOptions pco = (PythonCompilerOptions)engine.GetCompilerOptions(); pco.Module &= ~ModuleOptions.Optimized; engine.SetSearchPaths(new string[] { @"C:\Program Files\IronPython 2.7\Lib" }); ScriptRuntime runtime = engine.Runtime; ScriptScope scope = runtime.CreateScope(); var source = engine.CreateScriptSourceFromString( withLeak ? scriptWithLeak : scriptWithoutLeak ); var comped = source.Compile(); comped.Execute(scope); runtime.Shutdown(); }
public static void run(string path, Mml2vgmInfo info, int index) { ScriptEngine engine = null; ScriptRuntime runtime = null; try { engine = Python.CreateEngine(); var pc = HostingHelpers.GetLanguageContext(engine) as PythonContext; var hooks = pc.SystemState.Get__dict__()["path_hooks"] as List; hooks.Clear(); ScriptSource source = engine.CreateScriptSourceFromFile(path); CompiledCode code = source.Compile(); ScriptScope scope = engine.CreateScope(); runtime = engine.Runtime; Assembly assembly = typeof(Program).Assembly; runtime.LoadAssembly(Assembly.LoadFile(assembly.Location)); source.Execute(scope); dynamic pyClass = scope.GetVariable("Mml2vgmScript"); dynamic mml2vgmScript = pyClass(); ScriptInfo si = mml2vgmScript.run(info, index); if (si != null && info.document != null) { info.document.editor.azukiControl.Document.Replace(si.responseMessage); } } catch (Exception ex) { log.ForcedWrite(ex); } finally { runtime.Shutdown(); } }
public void Stop() { m_runtime.Shutdown(); }