本文整理汇总了C#中ScriptEngine.CreateScope方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptEngine.CreateScope方法的具体用法?C# ScriptEngine.CreateScope怎么用?C# ScriptEngine.CreateScope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScriptEngine
的用法示例。
在下文中一共展示了ScriptEngine.CreateScope方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IPRunner
public IPRunner(World world, GameEngine engine, Player player)
{
m_player = player;
m_scriptOutputStream = new MyStream(player.Send);
m_scriptEngine = IronPython.Hosting.Python.CreateEngine();
InitRuntime(m_scriptEngine.Runtime);
m_exprScope = m_scriptEngine.CreateScope();
InitScope(m_exprScope, world, engine, player);
m_scriptScope = m_scriptEngine.CreateScope();
InitScope(m_scriptScope, world, engine, player);
}
示例2: IronPythonCompletionProvider
/// <summary>
/// Class constructor
/// </summary>
public IronPythonCompletionProvider()
{
_engine = Python.CreateEngine();
_scope = _engine.CreateScope();
VariableTypes = new Dictionary<string, Type>();
ImportedTypes = new Dictionary<string, Type>();
RegexToType.Add(singleQuoteStringRegex, typeof(string));
RegexToType.Add(doubleQuoteStringRegex, typeof(string));
RegexToType.Add(doubleRegex, typeof(double));
RegexToType.Add(intRegex, typeof(int));
RegexToType.Add(arrayRegex, typeof(List));
RegexToType.Add(dictRegex, typeof(PythonDictionary));
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
if (assemblies.Any(x => x.FullName.Contains("RevitAPI")) && assemblies.Any(x => x.FullName.Contains("RevitAPIUI")))
{
try
{
_scope.Engine.CreateScriptSourceFromString("import clr\n", SourceCodeKind.Statements).Execute(_scope);
var revitImports =
"clr.AddReference('RevitAPI')\nclr.AddReference('RevitAPIUI')\nfrom Autodesk.Revit.DB import *\nimport Autodesk\n";
_scope.Engine.CreateScriptSourceFromString(revitImports, SourceCodeKind.Statements).Execute(_scope);
}
catch
{
DynamoLogger.Instance.Log("Failed to load Revit types for autocomplete. Python autocomplete will not see Autodesk namespace types.");
}
}
if (!assemblies.Any(x => x.FullName.Contains("LibGNet")))
{
AssemblyHelper.LoadLibG();
//refresh the assemblies collection
assemblies = AppDomain.CurrentDomain.GetAssemblies();
}
if (assemblies.Any(x => x.FullName.Contains("LibGNet")))
{
try
{
_scope.Engine.CreateScriptSourceFromString("import clr\n", SourceCodeKind.Statements).Execute(_scope);
var libGImports =
"import clr\nclr.AddReference('LibGNet')\nfrom Autodesk.LibG import *\n";
_scope.Engine.CreateScriptSourceFromString(libGImports, SourceCodeKind.Statements).Execute(_scope);
}
catch (Exception e)
{
DynamoLogger.Instance.Log(e.ToString());
DynamoLogger.Instance.Log("Failed to load LibG types for autocomplete. Python autocomplete will not see Autodesk namespace types.");
}
}
}
示例3: MainPage
public MainPage()
{
this.InitializeComponent();
var setup = new ScriptRuntimeSetup();
setup.HostType = typeof(DlrHost);
setup.AddRubySetup();
var runtime = Ruby.CreateRuntime(setup);
this.engine = Ruby.GetEngine(runtime);
this.scope = engine.CreateScope();
this.scope.SetVariable("Main", this);
runtime.LoadAssembly(typeof(object).GetTypeInfo().Assembly);
runtime.LoadAssembly(typeof(TextSetOptions).GetTypeInfo().Assembly);
runtime.LoadAssembly(typeof(TextAlignment).GetTypeInfo().Assembly);
string outputText = @"
box = main.find_name('OutputBox')
p box.text_alignment
box.text_alignment = Windows::UI::Xaml::TextAlignment.Right
p box.text_alignment
";
InputBox.IsSpellCheckEnabled = false;
OutputBox.IsSpellCheckEnabled = false;
InputBox.Document.SetText(TextSetOptions.None, outputText);
}
示例4: Main
/// <summary>
/// Main method
/// </summary>
/// <param name="args">Command line args.</param>
public static void Main(string[] args)
{
engine = Python.CreateEngine();
scope = engine.CreateScope();
engine.Runtime.LoadAssembly(typeof(TurntableBot).Assembly);
engine.Runtime.LoadAssembly(typeof(JObject).Assembly);
engine.Runtime.IO.RedirectToConsole();
ScriptSource source = null;
if (File.Exists(Script))
{
source = engine.CreateScriptSourceFromFile(Script);
}
else
{
Console.WriteLine("File not found");
}
if (source != null)
{
try
{
source.Execute(scope);
}
catch (Exception e)
{
ExceptionOperations ops = engine.GetService<ExceptionOperations>();
Console.WriteLine(ops.FormatException(e));
}
}
Console.ReadLine();
}
示例5: CreateRuntime
/// <summary>
/// Creates instances of the Ruby engine and Ruby scope
/// </summary>
public static void CreateRuntime()
{
_rubyRuntime = IronRuby.Ruby.CreateRuntime();
_rubyEngine = IronRuby.Ruby.GetEngine(_rubyRuntime);
_rubyScope = _rubyEngine.CreateScope();
_rubyEngine.Execute(@"load_assembly 'IronRuby.Libraries', 'IronRuby.StandardLibrary.Zlib'", _rubyScope);
}
示例6: Create
public ICondition Create()
{
_engine = Ruby.CreateEngine();
string rubyRuleTemplate;
using (var stream = Assembly.GetAssembly(this.GetType()).GetManifestResourceStream(_dslFileName))
{
using (var reader = new StreamReader(stream))
{
rubyRuleTemplate = reader.ReadToEnd();
}
}
rubyRuleTemplate = rubyRuleTemplate.Replace("$ruleAssembly$", _contextType.Namespace.Replace(".", "::"));
rubyRuleTemplate = rubyRuleTemplate.Replace("$contextType$", _contextType.Name);
rubyRuleTemplate = rubyRuleTemplate.Replace("$condition$", _condition);
_source = _engine.CreateScriptSourceFromString(rubyRuleTemplate);
var scope = _engine.CreateScope();
_assemblies.ForEach(a => _engine.Runtime.LoadAssembly(a));
_engine.Execute(_source.GetCode(), scope);
var @class = _engine.Runtime.Globals.GetVariable("RubyRuleFactory");
var installer = _engine.Operations.CreateInstance(@class);
var rule = installer.Create();
return (ICondition)rule;
}
示例7: RubyInstaller
public RubyInstaller(string fileName, List<Assembly> assemblies)
{
this.fileName = fileName;
assemblies.AddRange(new[] { typeof(IServiceLocator).Assembly, typeof(IConvention).Assembly });
if(engine == null)
{
lock(@lock)
{
if(engine == null)
{
engine = IronRuby.Ruby.CreateEngine();
scope = engine.CreateScope();
assemblies.ForEach(a => engine.Runtime.LoadAssembly(a));
LoadResource("Siege.ServiceLocator.Dynamic.Scripts.Installer.rb");
LoadResource("Siege.ServiceLocator.Dynamic.Scripts.SiegeDSL.rb");
LoadResource("Siege.ServiceLocator.Dynamic.Scripts.RubyRegistration.rb");
LoadResource("Siege.ServiceLocator.Dynamic.Scripts.RegistrationHandlers.RegistrationHandlerFactory.rb");
LoadResource("Siege.ServiceLocator.Dynamic.Scripts.RegistrationHandlers.DefaultRegistrationHandler.rb");
LoadResource("Siege.ServiceLocator.Dynamic.Scripts.RegistrationHandlers.DefaultInstanceRegistrationHandler.rb");
LoadResource("Siege.ServiceLocator.Dynamic.Scripts.RegistrationHandlers.ConditionalRegistrationHandler.rb");
LoadResource("Siege.ServiceLocator.Dynamic.Scripts.RegistrationHandlers.ConditionalInstanceRegistrationHandler.rb");
LoadResource("Siege.ServiceLocator.Dynamic.Scripts.RegistrationHandlers.NamedRegistrationHandler.rb");
LoadResource("Siege.ServiceLocator.Dynamic.Scripts.RegistrationHandlers.NamedInstanceRegistrationHandler.rb");
}
}
}
this.source = engine.CreateScriptSourceFromFile(this.fileName);
}
示例8: PythonScriptReader
public PythonScriptReader()
{
_engine = Python.CreateEngine();
_escope = _engine.CreateScope();
var reader = new StreamReader(new FileStream(@"Scripts\Script.py", FileMode.Open, FileAccess.Read));
string scriptText = reader.ReadToEnd();
reader.Close();
_engine.Execute(scriptText, _escope);
if (!_escope.TryGetVariable("GeneratorFunc", out _randomGenerator))
{
MessageBox.Show("Error Occurred in Executing python script! - GeneratorFunc", "Error");
throw new Exception("Error Occurred in Executing python script!");
}
if (!_escope.TryGetVariable("userDefinedFunc", out _userDefinedMethod))
{
MessageBox.Show("Error Occurred in Executing python script! - userDefinedFunc", "Error");
throw new Exception("Error Occurred in Executing python script!");
}
if (!_escope.TryGetVariable("LifeSpanMapper", out _lifeTimeMapper))
{
MessageBox.Show("Error Occurred in Executing python script! - LifeSpanMapper", "Error");
throw new Exception("Error Occurred in Executing python script!");
}
if (!_escope.TryGetVariable("DelayMapper", out _delayTimeMapper))
{
MessageBox.Show("Error Occurred in Executing python script! - DelayMapper", "Error");
throw new Exception("Error Occurred in Executing python script!");
}
}
示例9: IronPythonCompletionProvider
/// <summary>
/// Class constructor
/// </summary>
public IronPythonCompletionProvider()
{
_engine = Python.CreateEngine();
_scope = _engine.CreateScope();
VariableTypes = new Dictionary<string, Type>();
ImportedTypes = new Dictionary<string, Type>();
RegexToType.Add(singleQuoteStringRegex, typeof(string));
RegexToType.Add(doubleQuoteStringRegex, typeof(string));
RegexToType.Add(doubleRegex, typeof(double));
RegexToType.Add(intRegex, typeof(int));
RegexToType.Add(arrayRegex, typeof(List));
RegexToType.Add(dictRegex, typeof(PythonDictionary));
try
{
_scope.Engine.CreateScriptSourceFromString("import clr\n", SourceCodeKind.Statements).Execute(_scope);
var revitImports =
"clr.AddReference('RevitAPI')\nclr.AddReference('RevitAPIUI')\nfrom Autodesk.Revit.DB import *\nimport Autodesk\n";
_scope.Engine.CreateScriptSourceFromString(revitImports, SourceCodeKind.Statements).Execute(_scope);
}
catch
{
DynamoLogger.Instance.Log("Failed to load Revit types for autocomplete. Python autocomplete will not see Autodesk namespace types.");
}
}
示例10: Ruby
public Ruby()
{
//Setup the script engine runtime
var setup = new ScriptRuntimeSetup();
setup.LanguageSetups.Add(
new LanguageSetup(
"IronRuby.Runtime.RubyContext, IronRuby",
"IronRuby 1.0",
new[] { "IronRuby", "Ruby", "rb" },
new[] { ".rb" }));
setup.DebugMode = true;
//Create the runtime, engine, and scope
runtime = ScriptRuntime.CreateRemote(AppDomain.CurrentDomain, setup);
engine = runtime.GetEngine("Ruby");
scope = engine.CreateScope();
try
{
engine.Execute(@"$RGSS_VERSION = " + Program.GetRuntime().GetRGSSVersion(), scope);
engine.Execute(@"$GAME_DIRECTORY = '" + Program.GetRuntime().GetResourcePaths()[0].Replace(@"\", @"\\") + @"'", scope);
engine.Execute(@"$GAME_OS_WIN = " + Program.GetRuntime().IsWindowsOS().ToString().ToLower(), scope);
}
catch (Exception e)
{
Program.Error(e.Message);
}
//Load system internals and our Ruby internals
Console.WriteLine("Loading system");
//engine.Execute(System.Text.Encoding.UTF8.GetString(Properties.Resources.System), scope);
string script = System.Text.Encoding.UTF8.GetString(Properties.Resources.System);
script = script.Substring(1); //fix for a weird character that shouldn't be there o.O
Eval(script);
//Load the adaptable RPG datatypes
script = System.Text.Encoding.UTF8.GetString(Properties.Resources.RPG);
script = script.Substring(1);
Eval(script);
//Load the version appropriate RPG datatypes
if (Program.GetRuntime().GetRGSSVersion() == 1)
{
script = System.Text.Encoding.UTF8.GetString(Properties.Resources.RPG1);
script = script.Substring(1);
Eval(script);
}
if (Program.GetRuntime().GetRGSSVersion() == 2)
{
script = System.Text.Encoding.UTF8.GetString(Properties.Resources.RPG2);
script = script.Substring(1);
Eval(script);
}
if (Program.GetRuntime().GetRGSSVersion() == 3)
{
script = System.Text.Encoding.UTF8.GetString(Properties.Resources.RPG3);
script = script.Substring(1);
Eval(script);
}
}
示例11: InitialzeInterpreter
/// <summary>
/// 初始化解释器
/// </summary>
public void InitialzeInterpreter()
{
pythonEngine = Python.CreateEngine();
pythonScope = pythonEngine.CreateScope();
string initialString =
@"
import clr, sys
import System.Collections.Generic.List as List
clr.AddReference('Clover')
from Clover import *
# 获取CloverController的实例
clover = CloverController.GetInstance();
# 取出所有的函数指针
FindFacesByVertex = clover.FindFacesByVertex
GetVertex = clover.GetVertex
CutFaces = clover.AnimatedCutFaces
_CutFaces = clover.CutFaces
_RotateFaces = clover.RotateFaces
RotateFaces = clover.AnimatedRotateFaces
Undo = clover.Undo
Redo = clover.Redo
";
pythonEngine.Execute(initialString, pythonScope);
}
示例12: PythonTF
public PythonTF()
{
engine = Python.CreateEngine();
scope = engine.CreateScope();
Script = "value";
ScriptWorkMode = ScriptWorkMode.不进行转换;
}
示例13: Main
private static void Main()
{
try
{
PyEngine = Python.CreateEngine();
NtrClient = new NtrClient();
ScriptHelper = new ScriptHelper();
GlobalScope = PyEngine.CreateScope();
GlobalScope.SetVariable("nc", ScriptHelper);
LoadConfig();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
GCmdWindow = new CmdWindow();
Dc = new DebugConsole();
Application.Run(GCmdWindow);
}
catch (Exception e)
{
BugReporter br = new BugReporter(e, "Program exception");
MessageBox.Show(
@"WARNING - NTRDebugger has encountered an error" + Environment.NewLine +
@"This error is about to crash the program, please send the generated" + Environment.NewLine +
@"Error log to imthe666st!" + Environment.NewLine + Environment.NewLine +
@"Sorry for the inconvinience -imthe666st"
);
}
}
示例14: Engine
public Engine()
{
var options = new Dictionary<string, object>();
options["DivisionOptions"] = PythonDivisionOptions.New;
_history = new NullStream();
_output = new EventRaisingStreamWriter(_history);
_output.StringWritten += _output_StringWritten;
_engine = Python.CreateEngine(options);
_engine.Runtime.IO.SetOutput(_history, _output);
_engine.Runtime.IO.SetErrorOutput(_history, _output);
_scope = _engine.CreateScope();
foreach (var t in _pluggable)
{
_scope.SetVariable(t.Name, DynamicHelpers.GetPythonTypeFromType(t));
}
_scope.SetVariable("CalculatorFunctions", DynamicHelpers.GetPythonTypeFromType(typeof(CalculatorFunctions)));
_functioncache = new Dictionary<string, string>();
//hidden functions
_functioncache.Add("Var", "CalculatorFunctions.Var");
_functioncache.Add("FncList", "CalculatorFunctions.FncList");
_functioncache.Add("RegFunction", "CalculatorFunctions.RegFunction");
foreach (var f in _functions)
{
if (_functioncache.ContainsKey(f.Name)) continue;
_functioncache.Add(f.Name, f.FullName);
}
LoadBitops();
}
示例15: ScriptHost
public ScriptHost()
{
m_engine = Python.CreateEngine();
m_scope = m_engine.CreateScope();
CreateOutputBuffer();
}