コード例 #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
        private static LClosure Compile(string code)
        {
            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();

            return(_fastLuaCodeGen.Compile(ast, _fastLuaEnv));
        }