当前位置: 首页>>代码示例>>C#>>正文


C# ScriptEngine.Execute方法代码示例

本文整理汇总了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);
            }
        }
开发者ID:mattiascibien,项目名称:OpenGame.exe,代码行数:60,代码来源:Ruby.cs

示例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;
        }
开发者ID:kojoru,项目名称:GruntLauncher,代码行数:30,代码来源:GruntParser.cs

示例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();
        }
开发者ID:JamieDixon,项目名称:Web.Optimization,代码行数:33,代码来源:CoffeeScriptTransform.cs

示例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);
 }
开发者ID:JamesTryand,项目名称:cassette,代码行数:7,代码来源:LessCompiler.cs

示例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 "";
        }
开发者ID:offbyoneBB,项目名称:mp-onlinevideos2,代码行数:30,代码来源:Streamplay.cs

示例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;
 }
开发者ID:prabirshrestha,项目名称:cassette,代码行数:7,代码来源:JurassicCoffeeScriptCompiler.cs

示例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;
 }
开发者ID:stucampbell,项目名称:cassette,代码行数:8,代码来源:LessCompiler.cs

示例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 });
};");
        }
开发者ID:jlopresti,项目名称:cassette,代码行数:11,代码来源:HoganCompiler.cs

示例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 }); } });");
        }
开发者ID:Radnen,项目名称:sphere-sfml,代码行数:13,代码来源:GlobalScripts.cs

示例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);
        }
开发者ID:tomba,项目名称:dwarrowdelf,代码行数:15,代码来源:IPRunner.cs

示例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);
            }
        }
开发者ID:tjphilpot,项目名称:JurassicAccessViolation,代码行数:15,代码来源:Program.cs

示例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();
     }
 }
开发者ID:dusk0r,项目名称:Jurassic,代码行数:28,代码来源:Program.cs

示例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);
        }
开发者ID:cedricporter,项目名称:Clover,代码行数:29,代码来源:CloverInterpreter.cs

示例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;
        }
开发者ID:OxPatient,项目名称:Rule-Engine,代码行数:28,代码来源:RubyEngine.cs

示例15: Execute

 public override void Execute(ScriptEngine engine, ScriptScope scope)
 {
     if (!string.IsNullOrEmpty(Expression))
     {
         engine.Execute(Expression, scope);
     }
 }
开发者ID:torshy,项目名称:FileReplicator,代码行数:7,代码来源:ScriptExpression.cs


注:本文中的ScriptEngine.Execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。