本文整理汇总了C#中Microsoft.Scripting.Hosting.ScriptRuntime.GetEngine方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptRuntime.GetEngine方法的具体用法?C# ScriptRuntime.GetEngine怎么用?C# ScriptRuntime.GetEngine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.Scripting.Hosting.ScriptRuntime
的用法示例。
在下文中一共展示了ScriptRuntime.GetEngine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
try {
ScriptRuntimeSetup setup = ScriptRuntimeSetup.ReadConfiguration();
ScriptRuntime runtime = new ScriptRuntime(setup);
runtime.GetEngine("Python").Execute("print \"Hello, Hosted Script World!\"");
//runtime.ExecuteFile(PYTHON_FILE);
//ScriptScope scope = runtime.GetEngine("Python").CreateScope();
//scope.SetVariable("name", "John Zablocki");
#region func
//Func<string, string> reverse = (s) => {
// string reversed = "";
// for (int i = s.Length - 1; i >= 0; i--) {
// reversed += s[i];
// }
// return reversed;
// };
//scope.SetVariable("reverse", reverse);
#endregion
//runtime.GetEngine("Python").ExecuteFile(PYTHON_FILE, scope);
} catch (Exception ex) {
Console.WriteLine(ex.Message);
}
}
示例2: 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);
}
}
示例3: 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);
}
}
示例4: 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();
}
示例5: CompileModule
public static Action<HappyRuntimeContext> CompileModule(string filename)
{
ScriptRuntime runtime = new ScriptRuntime(ScriptRuntimeSetup.ReadConfiguration());
Microsoft.Scripting.Hosting.ScriptEngine engine = runtime.GetEngine("ht");
ScriptScope globals = engine.CreateScope();
var scriptSource = engine.CreateScriptSourceFromString(readFile(filename), filename, SourceCodeKind.File);
return scriptSource.Execute(globals);
}
示例6: Initialize
public void Initialize()
{
var setup = new ScriptRuntimeSetup();
var typeName = typeof (NaggumLanguageContext).AssemblyQualifiedName;
setup.LanguageSetups.Add(
new LanguageSetup(typeName, "Naggum", new[] { "naggum" }, new[] { ".naggum" }));
var runtime = new ScriptRuntime(setup);
_engine = runtime.GetEngine("naggum");
}
示例7: PyControllerFactory
static PyControllerFactory()
{
_setup = ScriptRuntimeSetup.ReadConfiguration();
_runtime = new ScriptRuntime(_setup);
_runtime.LoadAssembly(Assembly.GetExecutingAssembly());
string path = HttpContext.Current.Server.MapPath("~/App_Data/Controllers.py");
_runtime.GetEngine("IronPython").ExecuteFile(path, _runtime.Globals);
}
示例8: ReadConfiguration_1Lang
public void ReadConfiguration_1Lang() {
string configFile = GetTempConfigFile(new[]{LangSetup.Python});
var srs = ScriptRuntimeSetup.ReadConfiguration(configFile);
Assert.AreEqual(1, srs.LanguageSetups.Count);
var sr = new ScriptRuntime(srs);
Assert.AreEqual(1, sr.Setup.LanguageSetups.Count);
var pythonEngine = sr.GetEngine("py");
Assert.IsTrue(pythonEngine.IsValidPythonEngine());
}
示例9: Engine
/// <summary>
/// Initialises an instance
/// </summary>
/// <param name="languageSetup">Scripting language configuration object</param>
/// <param name="enableDebugging">Indicates whether script debugging should be enabled</param>
public Engine(LanguageSetup languageSetup, bool enableDebugging)
{
ScriptRuntimeSetup setup = new ScriptRuntimeSetup();
setup.LanguageSetups.Add(languageSetup);
setup.DebugMode = enableDebugging;
var runtime = new ScriptRuntime(setup);
var engine = runtime.GetEngine(setup.LanguageSetups[0].Names[0]);
_engine = engine;
_scope = _engine.CreateScope();
}
示例10: pythonEngine
public pythonEngine(String pythonFilename)
{
// Create a new engine and scope
ScriptRuntimeSetup setup = new ScriptRuntimeSetup();
setup.LanguageSetups.Add(IronPython.Hosting.Python.CreateLanguageSetup(null));
ScriptRuntime runtime = new ScriptRuntime(setup);
runtime.IO.RedirectToConsole();
_engine = runtime.GetEngine("IronPython");
_scope = _engine.CreateScope();
loadPythonFile(pythonFilename);
}
示例11: Configuration_MutateAndCheck3
public void Configuration_MutateAndCheck3()
{
string configFile = GetTempConfigFile(new[] { LangSetup.Python });
var sr = new ScriptRuntime(ScriptRuntimeSetup.ReadConfiguration(configFile));
var eng = sr.GetEngine("py");
var config = eng.Setup;
config = null;
Assert.IsNotNull(eng.Setup);
}
示例12: ReadConfiguration_All4Langs
public void ReadConfiguration_All4Langs() {
var srs = ScriptRuntimeSetup.ReadConfiguration(TestHelpers.StandardConfigFile);
Assert.AreEqual(2, srs.LanguageSetups.Count);
var runtime = new ScriptRuntime(srs);
foreach (var lang in srs.LanguageSetups) {
Assert.IsTrue((lang.Names != null) && (lang.Names.Count != 0));
//ensure this doesn't throw
var engine = runtime.GetEngine(lang.Names[0]);
Assert.AreEqual(lang.DisplayName, engine.Setup.DisplayName);
}
}
示例13: 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>();
}
示例14: GetObject
public object GetObject(string objectName)
{
Dictionary<string, object> instances = new Dictionary<string, object>();
ScriptRuntimeSetup setup = ScriptRuntimeSetup.ReadConfiguration();
ScriptRuntime runtime = new ScriptRuntime(setup);
runtime.LoadAssembly(Assembly.GetExecutingAssembly());
ScriptEngine engine = runtime.GetEngine("IronPython");
runtime.Globals.SetVariable("instances", instances);
engine.ExecuteFile("Objects.py", runtime.Globals);
return instances[objectName];
}
示例15: Window_Loaded
private void Window_Loaded(object sender, RoutedEventArgs e)
{
ScriptRuntimeSetup setup = new ScriptRuntimeSetup();
setup.LanguageSetups.Add(AplusCore.Runtime.AplusLanguageContext.LanguageSetup);
ScriptRuntime dlrRuntime = new ScriptRuntime(setup);
_engine = dlrRuntime.GetEngine(@"A+");
_ms = new MemoryStream();
var sw = new StreamWriter(_ms);
dlrRuntime.IO.SetErrorOutput(_ms, sw);
dlrRuntime.IO.SetOutput(_ms, sw);
_scope = _engine.CreateScope();
}