/// <summary> /// This method returns a language-specific service. /// /// It provides a point of extensibility for a language implementation /// to offer more functionality than the standard engine members discussed here. /// </summary> public TService GetService <TService>(params object[] args) where TService : class { if (typeof(TService) == typeof(TokenCategorizer)) { TokenizerService service = _language.GetService <TokenizerService>(ArrayUtils.Insert((object)_language, args)); return((service != null) ? (TService)(object)new TokenCategorizer(service) : null); } if (typeof(TService) == typeof(ExceptionOperations)) { ExceptionOperations service = _language.GetService <ExceptionOperations>(); return((service != null) ? (TService)(object)service : (TService)(object)new ExceptionOperations(_language)); } return(_language.GetService <TService>(args)); }
/// <summary> /// This method returns a language-specific service. /// /// It provides a point of extensibility for a language implementation /// to offer more functionality than the standard engine members discussed here. /// /// Commonly available services include: /// TokenCategorizer /// Provides standardized tokenization of source code /// ExceptionOperations /// Provides formatting of exception objects. /// DocumentationProvidera /// Provides documentation for live object. /// </summary> public TService GetService <TService>(params object[] args) where TService : class { if (typeof(TService) == typeof(TokenCategorizer)) { TokenizerService service = LanguageContext.GetService <TokenizerService>(ArrayUtils.Insert((object)LanguageContext, args)); return((service != null) ? (TService)(object)new TokenCategorizer(service) : null); } if (typeof(TService) == typeof(ExceptionOperations)) { ExceptionOperations service = LanguageContext.GetService <ExceptionOperations>(); return((service != null) ? (TService)(object)service : (TService)(object)new ExceptionOperations(LanguageContext)); } if (typeof(TService) == typeof(DocumentationOperations)) { DocumentationProvider service = LanguageContext.GetService <DocumentationProvider>(args); return((service != null) ? (TService)(object)new DocumentationOperations(service) : null); } return(LanguageContext.GetService <TService>(args)); }
static ScriptLanguage Compile(string path, out object compiled, out string error) { if (!System.IO.File.Exists(path)) { compiled = null; error = "Not found : " + path; return(ScriptLanguage.Unknown); } string ext = System.IO.Path.GetExtension(path); if (ext == ".cs") { var entryDirectory = Core.GetEntryDirectory() + "/"; // C# var lines = System.IO.File.ReadAllText(path); CompilerResults result = null; try { result = CSharpCodeProvider.CompileAssemblyFromSource(CompilerParameters, lines); } catch (Exception e) { compiled = null; error = "CSharp Compile Exception : " + path + "\n"; error += e.ToString(); return(ScriptLanguage.Unknown); } if (result.Errors.HasErrors) { compiled = null; error = "CSharp Compile Error : " + path + "\n"; for (int l = 0; l < result.Errors.Count; l++) { error += result.Errors[l] + "\n"; } return(ScriptLanguage.Unknown); } error = string.Empty; compiled = result; return(ScriptLanguage.CSharp); } else if (ext == ".py") { // Python var scope = PythonEngine.CreateScope(); try { var source = PythonEngine.CreateScriptSourceFromFile(path); var cc = source.Compile(); cc.Execute(scope); } catch (Microsoft.Scripting.SyntaxErrorException e) { Microsoft.Scripting.Hosting.ExceptionOperations eo = null; eo = PythonEngine.GetService <Microsoft.Scripting.Hosting.ExceptionOperations>(); compiled = null; error = "Python Compile Error : " + path + "\n"; error += eo.FormatException(e); return(ScriptLanguage.Unknown); } catch (Exception e) { compiled = null; error = e.ToString(); return(ScriptLanguage.Unknown); } error = string.Empty; compiled = scope; return(ScriptLanguage.Python); } compiled = null; error = "Undefined Extention Error: " + path + "\n"; return(ScriptLanguage.Unknown); }
internal MacroScriptEngine(string scriptType) { loadRunTime(); m_engine = m_runTime.GetEngine(scriptType); m_exceptionOperations = m_engine.GetService<ExceptionOperations>(); }