Exemple #1
0
        public void TestFile(string filename)
        {
            var file   = File.ReadAllText(filename);
            var engine = new ScriptEngine();
            var loader = new EngineFunctionLoader();

            loader.RegisterFunctions(engine);

            engine.Root.AddChild("result", new ScriptVar(0));

            ScriptException ex = null;

            try
            {
                engine.Execute(file);
            }
            catch (ScriptException e)
            {
                ex = e;
            }

            engine.Root.Trace(0, "root");

            var result       = engine.Root.GetParameter("result");
            var resultAsBool = result.Bool;

            Assert.IsTrue(resultAsBool, ex != null ? ex.Message : string.Empty);
        }
Exemple #2
0
        static void Main(string[] args)
        {
            var testScript = File.ReadAllText("testscript.js");

            var lexer = new ScriptLex(testScript);

            do
            {
                Console.WriteLine("{0,-16} | {1}", ScriptLex.LexTypesToString(lexer.TokenType), lexer.TokenString);
                lexer.GetNextToken();
            } while (lexer.TokenType != ScriptLex.LexTypes.Eof);

            var engine = new ScriptEngine();
            var loader = new EngineFunctionLoader();

            loader.RegisterFunctions(engine);


            engine.Trace();

            engine.Execute(testScript);
        }