예제 #1
0
파일: Program.cs 프로젝트: acaly/FastLua
        public static void Main()
        {
            var codeReader = new StringReader(_code);
            var rawTokens  = new LuaRawTokenizer();
            var luaTokens  = new LuaTokenizer();

            rawTokens.Reset(codeReader);
            luaTokens.Reset(rawTokens);

            var parser  = new LuaParser();
            var builder = new SyntaxTreeBuilder();

            builder.Start();
            luaTokens.EnsureMoveNext();
            parser.Reset(luaTokens, builder);
            parser.Parse();

            var ast = builder.Finish();

            var env = new Table();

            env.SetRaw(TypedValue.MakeString("print"), TypedValue.MakeNClosure(Print));

            var codeGen = new CodeGenerator();
            var closure = codeGen.Compile(ast, env);

            var thread = new Thread();
            var stack  = thread.AllocateRootCSharpStack(1);

            var arg = TypedValue.MakeString("C#");

            stack.Write(0, in arg);
            LuaInterpreter.Execute(stack, closure, 0, 1);
            stack.Read(0, out var ret);
        }
예제 #2
0
        static TestHelper()
        {
            AssertEnv = new Table();
            AssertEnv.SetRaw(TypedValue.MakeString("assert"), TypedValue.MakeNClosure(AssertFunc));

            DefaultEnv = new Table();
            DefaultEnv.SetRaw(TypedValue.MakeString("assert"), TypedValue.MakeNClosure(AssertFunc));
            DefaultEnv.SetRaw(TypedValue.MakeString("add"), TypedValue.MakeNClosure(AddFunc));
        }