本文整理汇总了C#中Microsoft.Scripting.Hosting.ScriptRuntime.GetEngineByTypeName方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptRuntime.GetEngineByTypeName方法的具体用法?C# ScriptRuntime.GetEngineByTypeName怎么用?C# ScriptRuntime.GetEngineByTypeName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Scripting.Hosting.ScriptRuntime
的用法示例。
在下文中一共展示了ScriptRuntime.GetEngineByTypeName方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetEngine
public ScriptEngine GetEngine()
{
if (_engine != null)
return _engine;
_engine = Python.CreateEngine();
ScriptRuntimeSetup setup = new ScriptRuntimeSetup();
setup.DebugMode = true;
setup.LanguageSetups.Add(Python.CreateLanguageSetup(null));
ScriptRuntime runtime = new ScriptRuntime(setup);
_engine = runtime.GetEngineByTypeName(typeof(PythonContext).AssemblyQualifiedName);
_engine.Runtime.IO.SetOutput(_stream, Encoding.UTF8);
_engine.Runtime.IO.SetErrorOutput(_stream, Encoding.UTF8);
string path = Environment.CurrentDirectory;
string ironPythonLibPath = string.Format(@"{0}\IronPythonLib.zip", path);
var paths = _engine.GetSearchPaths() as List<string> ?? new List<string>();
paths.Add(path);
paths.Add(ironPythonLibPath);
path = Environment.GetEnvironmentVariable("IRONPYTHONPATH");
if (!string.IsNullOrEmpty(path))
{
var pathStrings = path.Split(';');
paths.AddRange(pathStrings.Where(p => p.Length > 0));
}
_engine.SetSearchPaths(paths.ToArray());
return _engine;
}
示例2: BonsaiTestClass
public BonsaiTestClass()
{
ScriptRuntimeSetup runtimeSetup = new ScriptRuntimeSetup() {
DebugMode = true,
LanguageSetups = {
new LanguageSetup(
typeof(BonsaiContext).AssemblyQualifiedName,
"Bonsai",
new string[] {"Bonsai"},
new string[] {".bon"})
}
};
ScriptRuntime runtime = new ScriptRuntime(runtimeSetup);
ScriptScope global = runtime.CreateScope();
scriptEngineInstance = runtime.GetEngineByTypeName(typeof(BonsaiContext).AssemblyQualifiedName);
}
示例3: Main
public static void Main(string[] args)
{
ScriptRuntimeSetup runtimeSetup = new ScriptRuntimeSetup() {
DebugMode = true,
LanguageSetups = {
new LanguageSetup(
typeof(BonsaiContext).AssemblyQualifiedName,
"Bonsai",
new string[] {"Bonsai"},
new string[] {".bon"})
}
};
ScriptRuntime runtime = new ScriptRuntime(runtimeSetup);
ScriptScope global = runtime.CreateScope();
ScriptEngine engine = runtime.GetEngineByTypeName(typeof(BonsaiContext).AssemblyQualifiedName);
var result = engine.Execute(File.ReadAllText("Test.bon"));
string line;
while((line = Console.ReadLine()).Length > 0) {
result = engine.Execute(line);
Console.WriteLine(result);
}
}
示例4: PythonObject
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);
}
示例5: GetEngine
/// <summary>
/// Given a ScriptRuntime gets the ScriptEngine for IronPython.
/// </summary>
public static ScriptEngine/*!*/ GetEngine(ScriptRuntime/*!*/ runtime) {
return runtime.GetEngineByTypeName(typeof(PythonContext).AssemblyQualifiedName);
}
示例6: ResetEngine
public void ResetEngine(bool debugmode = false)
{
if(_python != null)
_python.Runtime.Shutdown();
ScriptRuntimeSetup setup = new ScriptRuntimeSetup();
setup.DebugMode = debugmode;
setup.LanguageSetups.Add(Python.CreateLanguageSetup(null));
ScriptRuntime runtime = new ScriptRuntime(setup);
_python = runtime.GetEngineByTypeName(typeof(PythonContext).AssemblyQualifiedName);
LoadAssembly(typeof(Prefab.Bitmap).Assembly);
LoadAssembly(typeof(PrefabUtils.PathDescriptor).Assembly);
if(_consoleOutput == null)
_consoleOutput = new MemoryStream();
_python.Runtime.IO.SetOutput(_consoleOutput, Encoding.Default);
// _python.Runtime.GetClrModule().GetVariable("AddReference")("Prefab");
//_python = runtime.GetEngineByTypeName(typeof(PythonContext).AssemblyQualifiedName);
//Instance = new PythonScriptHost(false);
}
示例7: GetEngine
/// <summary>
/// Retrieves an IronRuby engine from a given script runtime.
/// </summary>
/// <param name="runtime">The runtime to get the engine from.</param>
/// <returns>An IronRuby engine from the specified runtime.</returns>
/// <exception cref="ArgumentException">
/// The <paramref name="runtime"/> is not set up to run IronRuby.
/// The <see cref="ScriptRuntimeSetup"/> doesn't contain IronRuby's <see cref="ScriptLanguageSetup"/>.
/// </exception>
public static ScriptEngine/*!*/ GetEngine(ScriptRuntime/*!*/ runtime) {
ContractUtils.RequiresNotNull(runtime, "runtime");
return runtime.GetEngineByTypeName(typeof(RubyContext).AssemblyQualifiedName);
}
示例8: GetEngine
///-------------------------------------------------------------------------------------------------
/// <summary> Given a ScriptRuntime gets the ScriptEngine for IronTotem. </summary>
///
/// <remarks> Aleksander, 14.04.2013. </remarks>
///
/// <param name="runtime"> The runtime. </param>
///
/// <returns> The engine. </returns>
///-------------------------------------------------------------------------------------------------
public static ScriptEngine GetEngine(ScriptRuntime runtime)
{
return runtime.GetEngineByTypeName(typeof(TotemContext).AssemblyQualifiedName);
}
示例9: CreateEngine
/// <summary>
/// Create new scripting engine
/// </summary>
/// <param name="runtime">Instance of the current runtime enviroement</param>
/// <returns>Instance of IP script engine</returns>
public ScriptEngine CreateEngine(ScriptRuntime runtime)
{
scriptEngine = runtime.GetEngineByTypeName(typeof(PythonContext).AssemblyQualifiedName);
// Override import functionality
ScriptScope scope = IronPython.Hosting.Python.GetBuiltinModule(scriptEngine);
scope.SetVariable("__import__", new ImportDelegate(ResolveImport));
var sysScope = scriptEngine.GetSysModule();
List path_hooks = sysScope.GetVariable("path_hooks");
// Disable zipimporter if needed
for (int i = 0; i < path_hooks.Count; i++)
{
if (path_hooks.ElementAt(i) != null)
{
PythonType type = path_hooks.ElementAt(i) as PythonType;
string name = PythonType.Get__name__(type);
if (name == "zipimporter" && EnableZipImporter == false)
{
path_hooks.RemoveAt(i);
}
}
}
PythonType genericimporter = DynamicHelpers.GetPythonType(new GenericImportModule.genericimporter());
path_hooks.Add(genericimporter);
sysScope.SetVariable("path_hooks", path_hooks);
return scriptEngine;
}