本文整理汇总了C#中ScriptEngine.GetSysModule方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptEngine.GetSysModule方法的具体用法?C# ScriptEngine.GetSysModule怎么用?C# ScriptEngine.GetSysModule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScriptEngine
的用法示例。
在下文中一共展示了ScriptEngine.GetSysModule方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitializePythonEngine
private void InitializePythonEngine()
{
_engine = Python.CreateEngine(new Dictionary<string, object> {{"PrivateBinding", true}});
_output = new FileToLog(_logger);
// redirecionar o output para a caixa de texto
_engine.GetSysModule().SetVariable("stdout", _output);
_engine.GetSysModule().SetVariable("stderr", _output);
// outra hipotese seria interceptar IO em _engine.Runtime.IO
_engine.Runtime.LoadAssembly(GetType().Assembly);
foreach (var referencedAssembly in GetType().Assembly.GetReferencedAssemblies())
{
_engine.Runtime.LoadAssembly(Assembly.Load(referencedAssembly));
}
}
示例2: 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;
}