本文整理汇总了C#中Microsoft.Scripting.Hosting.ScriptRuntime.CreateScope方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptRuntime.CreateScope方法的具体用法?C# ScriptRuntime.CreateScope怎么用?C# ScriptRuntime.CreateScope使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Scripting.Hosting.ScriptRuntime
的用法示例。
在下文中一共展示了ScriptRuntime.CreateScope方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
// set path for dynamic assembly loading
AppDomain.CurrentDomain.AssemblyResolve +=
new ResolveEventHandler(ResolveAssembly);
string path = System.IO.Path.Combine(exe_path, py_path);
pyscript = System.IO.Path.Combine(path, pyscript);
pyscript = System.IO.Path.GetFullPath(pyscript); // normalize
// get runtime
ScriptRuntimeSetup scriptRuntimeSetup = new ScriptRuntimeSetup();
LanguageSetup language = Python.CreateLanguageSetup(null);
language.Options["Debug"] = true;
scriptRuntimeSetup.LanguageSetups.Add(language);
ScriptRuntime runtime = new Microsoft.Scripting.Hosting.ScriptRuntime(scriptRuntimeSetup);
// set sys.argv
SetPyEnv(runtime, pyscript, args);
// get engine
ScriptScope scope = runtime.CreateScope();
ScriptEngine engine = runtime.GetEngine("python");
ScriptSource source = engine.CreateScriptSourceFromFile(pyscript);
source.Compile();
try {
source.Execute(scope);
} catch (IronPython.Runtime.Exceptions.SystemExitException e) {
Console.WriteLine(e.StackTrace);
}
}
示例2: register
public void register()
{
engine = Python.CreateEngine();
scope = null;
runtime = engine.Runtime;
scope = runtime.CreateScope();
}
示例3: IronPythonScriptEngine
public IronPythonScriptEngine()
{
runtime = engine.Runtime;
runtime.LoadAssembly(Assembly.GetAssembly(typeof(Mogre.Vector3)));
scope = runtime.CreateScope();
// install built-in scripts
install(new Script(builtin));
}
示例4: RunProgram
public void RunProgram()
{
engine = Python.CreateEngine();
runtime = engine.Runtime;
scope = runtime.CreateScope();
RunExpression();
RunInScope();
RunFromFile();
}
示例5: ValidateGetItems
private void ValidateGetItems(ScriptRuntime runtime) {
ScriptScope scope = runtime.CreateScope();
var dict = new KeyValuePair<string, object>("var1", 1);
scope.SetVariable(dict.Key, dict.Value);
TestHelpers.AreEqualCollections<KeyValuePair<string, object>>(new[] { dict }, scope.GetItems());
var newDict = new KeyValuePair<string, object>("newVar", "newval");
scope.SetVariable(newDict.Key, newDict.Value);
TestHelpers.AreEqualCollections<KeyValuePair<string, object>>(new[] { dict, newDict }, scope.GetItems());
}
示例6: Scripting
public Scripting()
{
Host = Python.CreateRuntime();
Scope = Host.CreateScope();
Engine = Host.GetEngine("Python");
PacketHooks = new Dictionary<NSCommand, List<PacketHookCall>>();
UpdateHooks = new List<UpdateHookCall>();
ChatHooks = new List<ChatHookCall>();
ChatCommandHooks = new Dictionary<string, List<ChatCommandHookCall>>();
NameFormatHooks = new List<NameFormatHookCall>();
PlayerXPHooks = new List<PlayerXPHookCall>();
}
示例7: AnalysisModule
public AnalysisModule()
{
var t = Directory.GetCurrentDirectory();
SourcePath = t + "\\Analysis";
if (!Directory.Exists(SourcePath))
{
Directory.CreateDirectory(SourcePath);
}
ASRT = new ScriptRuntime(ScriptRuntimeSetup.ReadConfiguration(t+"\\NSCore.dll.config"));
ASRT.LoadAssembly(Assembly.GetAssembly(typeof(IDevice)));
ASRT.LoadAssembly(Assembly.GetAssembly(typeof(Marshal)));
Scope = ASRT.CreateScope();
}
示例8: RubyEngine
public RubyEngine(object appScope)
{
var runtimeSetup = new ScriptRuntimeSetup();
runtimeSetup
.LanguageSetups
.Add(new LanguageSetup("IronRuby.Runtime.RubyContext, IronRuby",
"IronRuby 1.0",
new[] { "IronRuby", "Ruby", "rb" },
new[] { ".rb" }));
runtime = ScriptRuntime.CreateRemote(AppDomain.CurrentDomain, runtimeSetup);
scope = runtime.CreateScope();
scope.SetVariable("app", appScope);
engine = runtime.GetEngine("IronRuby");
}
示例9: HAPITestBase
protected HAPITestBase() {
var ses = CreateSetup();
ses.HostType = typeof(TestHost);
_runtime = new ScriptRuntime(ses);
_remoteRuntime = ScriptRuntime.CreateRemote(TestHelpers.CreateAppDomain("Alternate"), ses);
_runTime = _runtime;// _remoteRuntime;
_PYEng = _runTime.GetEngine("py");
_RBEng = _runTime.GetEngine("rb");
SetTestLanguage();
_defaultScope = _runTime.CreateScope();
_codeSnippets = new PreDefinedCodeSnippets();
}
示例10: Main
static void Main(string[] args)
{
var runtimeSetup = Python.CreateRuntimeSetup(new Dictionary<string, object>());
runtimeSetup.DebugMode = true;
var runtime = new ScriptRuntime(runtimeSetup);
var scope = runtime.CreateScope(new Dictionary<string, object> {
{ "name" , "Batman" }
});
var engine = runtime.GetEngine("py");
var scriptSource = engine.CreateScriptSourceFromFile("script.py");
var compiledCode = scriptSource.Compile();
compiledCode.Execute(scope);
}
示例11: 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);
}
示例12: eval
protected bool eval(string script, object propertyValue)
{
ScriptRuntimeSetup setup = ScriptRuntimeSetup.ReadConfiguration();
ScriptRuntime runtime = new ScriptRuntime(setup);
ScriptScope scope = runtime.CreateScope("IronPython");
scope.SetVariable("property_value", propertyValue);
scope.SetVariable("result", true);
scope.Engine.CreateScriptSourceFromString("import clr", SourceCodeKind.SingleStatement).Execute(scope);
scope.Engine.CreateScriptSourceFromString("clr.AddReference('System')", SourceCodeKind.SingleStatement).Execute(scope);
scope.Engine.CreateScriptSourceFromString("from System import *", SourceCodeKind.SingleStatement).Execute(scope);
ScriptSource source = scope.Engine.CreateScriptSourceFromString(script, SourceCodeKind.Statements);
source.Execute(scope);
bool result = (bool)scope.GetVariable("result");
return result;
}
示例13: ConstructObject
protected object ConstructObject(ContainedObject co)
{
if (_staticObjects.ContainsKey(co.Name)) {
return _staticObjects[co.Name];
} else {
//in the full CodeVoyeur version, this is cached!
ScriptRuntimeSetup setup = ScriptRuntimeSetup.ReadConfiguration();
ScriptRuntime runtime = new ScriptRuntime(setup);
runtime.LoadAssembly(Assembly.GetExecutingAssembly());
ScriptScope scope = runtime.CreateScope("IronPython");
ScriptSource source = scope.Engine.CreateScriptSourceFromString("from HostedIronPython.Model import *", SourceCodeKind.SingleStatement);
source.Execute(scope);
scope.SetVariable("instance", new object());
scope.SetVariable("reference", new Func<string, object>
(
delegate(string refName) {
if (_staticObjects.ContainsKey(refName))
return _staticObjects[refName];
else
return GetFilling(refName);
}
));
ScriptSource configSource = scope.Engine.CreateScriptSourceFromString(co.Script, SourceCodeKind.Statements);
configSource.Execute(scope);
if (co.IsStatic)
return _staticObjects[co.Name] = scope.GetVariable("instance");
else
return scope.GetVariable("instance");
}
}
示例14: 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);
}
}
示例15: getQuery
private Func<Album, bool> getQuery(string queryName, string searchParam)
{
XDocument doc = XDocument.Load("AlbumQueries.xml");
var query = (from q in doc.Descendants("query")
where q.Attribute("name").Value == queryName
select new {
Query = q.Value
}).FirstOrDefault();
ScriptRuntimeSetup setup = ScriptRuntimeSetup.ReadConfiguration();
ScriptRuntime runtime = new ScriptRuntime(setup);
ScriptScope scope = runtime.CreateScope("IronPython");
scope.SetVariable("search_param", searchParam);
scope.Engine.CreateScriptSourceFromString("import clr", SourceCodeKind.SingleStatement).Execute(scope);
scope.Engine.CreateScriptSourceFromString("clr.AddReference('System')", SourceCodeKind.SingleStatement).Execute(scope);
scope.Engine.CreateScriptSourceFromString("from System import *", SourceCodeKind.SingleStatement).Execute(scope);
ScriptSource source = scope.Engine.CreateScriptSourceFromString(query.Query, SourceCodeKind.Statements);
source.Execute(scope);
return scope.GetVariable<Func<Album, bool>>("query");
}