本文整理汇总了C#中ScriptEngine.GetBuiltinModule方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptEngine.GetBuiltinModule方法的具体用法?C# ScriptEngine.GetBuiltinModule怎么用?C# ScriptEngine.GetBuiltinModule使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScriptEngine
的用法示例。
在下文中一共展示了ScriptEngine.GetBuiltinModule方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Form1
public Form1()
{
InitializeComponent();
_options = new Dictionary<string, object>();
Python.CreateRuntimeSetup(_options);
_options.Add("Frames", true);
_engine = Python.CreateRuntime(_options).GetEngine("python");//setup.Options["Frames"] = true;
try
{
_builtin = _engine.GetBuiltinModule();
SetWorkDir();
_scope = _engine.CreateScope();
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message, "Error initialization");
}
}
示例2: InitializePython
/// <summary>
/// Initializes the Python engine
/// </summary>
private void InitializePython()
{
// Create the Python engine
PythonEngine = IronPython.Hosting.Python.CreateEngine();
var paths = PythonEngine.GetSearchPaths();
paths.Add(Path.Combine(Interface.GetMod().InstanceDirectory, "Lib"));
PythonEngine.SetSearchPaths(paths);
PythonEngine.GetBuiltinModule().SetVariable("__import__", new ImportDelegate(DoImport));
PythonEngine.GetBuiltinModule().RemoveVariable("execfile");
PythonEngine.GetBuiltinModule().RemoveVariable("exit");
PythonEngine.GetBuiltinModule().RemoveVariable("file");
PythonEngine.GetBuiltinModule().RemoveVariable("input");
PythonEngine.GetBuiltinModule().RemoveVariable("open");
PythonEngine.GetBuiltinModule().RemoveVariable("raw_input");
PythonEngine.GetBuiltinModule().RemoveVariable("reload");
PythonEngine.Execute(
@"class Command:
def __init__(self, *dec_args, **dec_kw):
self.dec_args = dec_args
self.dec_kw = dec_kw
self.name = list(self.dec_args)
self.permission = []
name = self.dec_kw.get('name', [])
if not isinstance(name, list):
name = [name]
self.name = self.name + name
permission = self.dec_kw.get('permission', [])
if not isinstance(permission, list):
permission = [permission]
self.permission = self.permission + permission
permission = self.dec_kw.get('permissions', [])
if not isinstance(permission, list):
permission = [permission]
self.permission = self.permission + permission
def __call__(self, f):
self.f = f
self.f.isCommand = True
self.f.name = self.name
self.f.permission = self.permission
return self.f", PythonEngine.GetBuiltinModule());
}
示例3: InitializeEngine
/// <summary> スクリプティングAPIの設定にもとづいて初期化を行う </summary>
/// <param name="api">APIとなるインスタンス</param>
/// <param name="globals">グローバル変数</param>
private void InitializeEngine(IScriptApi api, PythonDictionary globals)
{
_ironPythonEngine = Python.CreateEngine();
//名前参照にexeのディレクトリとキャラのディレクトリを追加
var paths = _ironPythonEngine.GetSearchPaths();
paths.Add(Environment.CurrentDirectory);
paths.Add(DirectoryNames.GetCharacterScriptDirectory(api.CharacterName));
_ironPythonEngine.SetSearchPaths(paths);
//可視領域を限界まで広く取るためビルトインスコープにぶち込んでおく
ScriptScope builtin = _ironPythonEngine.GetBuiltinModule();
builtin.SetVariable(IronPythonCommonVariableNames.ApiVariableName, api);
builtin.SetVariable(IronPythonCommonVariableNames.ApiGlobalDictionaryName, globals);
}