Unity captures IronPython script error

Source: Internet
Author: User
Tags hosting

Using system;using system.collections.generic;using system.io;using system.reflection;using System.Text;using System.windows.forms;using ironpython.hosting;using ironpython.runtime;using ironpython.runtime.exceptions;using Microsoft.scripting;using microsoft.scripting.runtime;using microsoft.scripting.hosting;using Plugins;namespace        embeddingplugin{internal class Pythonstream:memorystream {TextBox _output;        Public Pythonstream (textbox textbox) {_output = textbox; public override void Write (byte[] buffer, int offset, int count) {_output.        AppendText (Encoding.UTF8.GetString (buffer, offset, count));        }} internal class Engine {ScriptEngine _engine;        Scriptruntime _runtime;        TextBox _box;        Public list<pluginbase> Plugins {get {return pluginstore.plugins;} Public Engine (textbox textbox) {_engine = Python.createengine(); _runtime = _engine.            Runtime;            _box = textbox;            Setstreams ();            String rootdir = Addassemblies ();        Loadplugins (RootDir);            } public void Setstreams () {Pythonstream stream = new Pythonstream (_box); _runtime. Io.            Setoutput (stream, Encoding.UTF8); _runtime. Io.        Seterroroutput (stream, Encoding.UTF8);            The public string addassemblies () {Assembly mainassembly = assembly.getexecutingassembly (); String RootDir = Directory.getparent (mainassembly.location).            FullName;            String pluginspath = Path.Combine (RootDir, "Plugins.dll");            Assembly pluginsassembly = Assembly.loadfile (Pluginspath); _runtime.            LoadAssembly (mainassembly); _runtime.            LoadAssembly (pluginsassembly); _runtime. LoadAssembly (typeof (String).            Assembly); _runtime. LoadAssembly (typeof (Uri).            Assembly);        return rootdir;        }public void Loadplugins (string rootdir) {string pluginsdir = Path.Combine (RootDir, "plugins"); foreach (String path in Directory.GetFiles (Pluginsdir)) {if (path. ToLower ().                EndsWith (". Py")) {Createplugin (path); }}} public void Createplugin (string path) {try {S Criptsource script = _engine.                Createscriptsourcefromfile (path);                Compiledcode code = script.compile (); Scriptscope scope = _engine.                Createscope (); Script.            Execute (scope);                } catch (Syntaxerrorexception e) {string msg = "Syntax error in \" {0}\ "";            ShowError (msg, Path.getfilename (Path), E);                } catch (Systemexitexception e) {string msg = "Systemexit in \" {0}\ ""; ShowError (MSG, Path.getfilename (PAth), E);                } catch (Exception e) {string msg = "Error loading plugin \" {0}\ "";            ShowError (msg, Path.getfilename (Path), E); }} public void ShowError (string title, string name, Exception e) {String caption = Strin            G.format (title, name); Exceptionoperations eo = _engine.            Getservice<exceptionoperations> (); String error = EO.            FormatException (e);        MessageBox.Show (Error, caption, MessageBoxButtons.OK, messageboxicon.error);            } public void Executepluginatindex (int index) {pluginbase plugin = Plugins[index]; try {plugin.            Execute (_box);                } catch (Exception e) {string msg = "Error executing plugin \" {0}\ ""; ShowError (msg, plugin.            Name, E); }        }    }}

  

Unity captures IronPython script error

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.