本文整理汇总了C#中ScriptEngine.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptEngine.Execute方法的具体用法?C# ScriptEngine.Execute怎么用?C# ScriptEngine.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ScriptEngine
的用法示例。
在下文中一共展示了ScriptEngine.Execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: ReadAllTasks
/// <summary>
/// Reads all the defined tasks in a Gruntfile whose path is passed as parameter
/// </summary>
/// <param name="path">The path of the file to examine</param>
/// <returns>A list of tasks</returns>
public static ICollection<string> ReadAllTasks(string path)
{
var list = new List<string>();
//executes the gruntfile with some little additions :)
try
{
var engine = new ScriptEngine();
engine.Execute(Resources.Init);
engine.ExecuteFile(path);
engine.Execute("module.exports(grunt);");
//reads the evaluated tasks
ArrayInstance names = (ArrayInstance)engine.Evaluate("names");
foreach (var elem in names.ElementValues)
{
list.Add((string)elem);
}
}
catch (Exception) {
list.Add("Cannot parse Gruntfile");
}
return list;
}
示例3: Process
public void Process(BundleContext context, BundleResponse response)
{
var coffeeScriptPath =
Path.Combine(
HttpRuntime.AppDomainAppPath,
"Scripts",
"coffee-script.js");
if (!File.Exists(coffeeScriptPath))
{
throw new FileNotFoundException(
"Could not find coffee-script.js beneath the ~/Scripts directory.");
}
var coffeeScriptCompiler =
File.ReadAllText(coffeeScriptPath, Encoding.UTF8);
var engine = new ScriptEngine();
engine.Execute(coffeeScriptCompiler);
// Initializes a wrapper function for the CoffeeScript compiler.
var wrapperFunction =
string.Format(
"var compile = function (src) {{ return CoffeeScript.compile(src, {{ bare: {0} }}); }};",
_bare.ToString(CultureInfo.InvariantCulture).ToLower());
engine.Execute(wrapperFunction);
var js = engine.CallGlobalFunction("compile", response.Content);
response.ContentType = ContentTypes.JavaScript;
response.Content = js.ToString();
}
示例4: LessCompiler
public LessCompiler()
{
engine = new ScriptEngine();
engine.Execute("window = { location: { href: '/', protocol: 'http:', host: 'localhost' } };");
engine.SetGlobalFunction("xhr", new Action<ObjectInstance, ObjectInstance, FunctionInstance, FunctionInstance>(Xhr));
engine.Execute(Properties.Resources.less);
}
示例5: GetVideoUrl
public override string GetVideoUrl(string url)
{
if(!url.Contains("embed-"))
{
url = url.Replace("play.to/", "play.to/embed-");
}
if (!url.EndsWith(".html"))
{
url += ".html";
}
string data = GetWebData<string>(url);
Regex rgx = new Regex(@">eval(?<js>.*?)</script>", RegexOptions.Singleline);
Match m = rgx.Match(data);
if (m.Success)
{
ScriptEngine engine = new ScriptEngine();
string js = m.Groups["js"].Value;
engine.Execute("var player = " + js + ";");
engine.Execute("function getPlayer() { return player; };");
data = engine.CallGlobalFunction("getPlayer").ToString();
rgx = new Regex(@"file:""(?<url>http[^""]*?.mp4)""");
m = rgx.Match(data);
if (m.Success)
{
return m.Groups["url"].Value;
}
}
return "";
}
示例6: CreateScriptEngineWithCoffeeScriptLoaded
static ScriptEngine CreateScriptEngineWithCoffeeScriptLoaded()
{
var engine = new ScriptEngine();
engine.Execute(Properties.Resources.coffeescript);
engine.Execute("function compile(c) { return CoffeeScript.compile(c); }");
return engine;
}
示例7: CreateScriptEngine
static ScriptEngine CreateScriptEngine()
{
var engine = new ScriptEngine();
const string stubWindowLocationForCompiler = "window = { location: { href: '/', protocol: 'http:', host: 'localhost' } };";
engine.Execute(stubWindowLocationForCompiler);
engine.Execute(Properties.Resources.less);
return engine;
}
示例8: HoganCompiler
public HoganCompiler()
{
scriptEngine = new ScriptEngine();
scriptEngine.Execute(Properties.Resources.hogan);
// Create a global compile function that returns the template compiled into javascript source.
scriptEngine.Execute(@"
var compile = function (template) {
return Hogan.compile(template, { asString: true });
};");
}
示例9: BindToEngine
public static void BindToEngine(ScriptEngine engine)
{
engine.SetGlobalFunction("RequireScript", new Action<string>(RequireScript));
engine.SetGlobalFunction("RequireSystemScript", new Action<string>(RequireSystemScript));
engine.SetGlobalFunction("EvaluateScript", new Action<string>(EvaluateScript));
engine.SetGlobalFunction("EvaluateSystemScript", new Action<string>(EvaluateSystemScript));
engine.Execute("Object.defineProperty(Object.prototype, \"__defineGetter__\", { value: function(name, func) {" +
"Object.defineProperty(this, name, { get: func, configurable: true }); } });");
engine.Execute("Object.defineProperty(Object.prototype, \"__defineSetter__\", { value: function(name, func) {" +
"Object.defineProperty(this, name, { set: func, configurable: true }); } });");
}
示例10: IPRunner
public IPRunner(Action<string> sender)
{
m_sender = sender;
m_scriptOutputStream = new MyStream(sender);
m_scriptEngine = IronPython.Hosting.Python.CreateEngine();
m_scriptEngine.Runtime.IO.SetOutput(m_scriptOutputStream, System.Text.Encoding.Unicode);
m_scriptEngine.Runtime.IO.SetErrorOutput(m_scriptOutputStream, System.Text.Encoding.Unicode);
m_scriptScope = m_scriptEngine.CreateScope();
m_scriptEngine.Execute("import clr", m_scriptScope);
m_scriptEngine.Execute("clr.AddReference('Dwarrowdelf.Common')", m_scriptScope);
m_scriptEngine.Execute("import Dwarrowdelf", m_scriptScope);
}
示例11: Main
static void Main(string[] args)
{
string xmlDomJs = File.ReadAllText("xmldom.js");
string loadAbbrevsJs = File.ReadAllText("loadabbrevs.js");
string citeprocJs = File.ReadAllText("citeproc.js");
for (int i = 0; i < 100; i++)
{
Console.WriteLine("Loading into engine - attempt {0}", i);
ScriptEngine engine = new ScriptEngine();
engine.Execute(xmlDomJs);
engine.Execute(loadAbbrevsJs);
engine.Execute(citeprocJs);
}
}
示例12: Main
static void Main(string[] args)
{
for (; ; )
{
ScriptEngine sr = new ScriptEngine();
StringBuilder sb = new StringBuilder();
for (; ; )
{
string txt = Console.ReadLine();
if (txt == "::exit::")
return;
if (txt == "::end::")
break;
sb.AppendLine(txt);
}
try
{
sr.Execute(sb.ToString());
Console.WriteLine("::pass::");
}
catch (Exception e)
{
Console.WriteLine(e);
}
Console.WriteLine("::fin::");
Console.Out.Flush();
}
}
示例13: 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);
}
示例14: 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;
}
示例15: Execute
public override void Execute(ScriptEngine engine, ScriptScope scope)
{
if (!string.IsNullOrEmpty(Expression))
{
engine.Execute(Expression, scope);
}
}