static Func<dynamic> CompileString(CodeContext context, string source) { ContractUtils.RequiresNotNull(context, "context"); var sourceUnit = context.Language.CreateSnippet(source, SourceCodeKind.Statements); //var options = (LuaCompilerOptions)context.GetCompilerOptions(); //var errorSink = context.GetCompilerErrorSink(); //var lexer = context.GetService<TokenizerService>(); var lexer = new Tokenizer(ErrorSink.Default, LuaCompilerOptions.Default); lexer.Initialize(null, sourceUnit.GetReader(), sourceUnit, SourceLocation.MinValue); var parser = new Parser(lexer, lexer.ErrorSink); var ast = parser.Parse(); var gen = new Generator(context); var fnStack =context.FunctionStacks.LastOrDefault(x => x.ExecScope != null); if (fnStack == default(FunctionStack)) fnStack = new FunctionStack(context, null, LuaScope.CreateRoot(context), "=(compiled code)"); var expr = gen.CompileInline(ast, fnStack.ExecScope, context.ExecutingScopeStorage, sourceUnit); return expr.Compile(); }
private List<FunctionStack> _PushFunctionStack(FunctionStack function) { _FunctionStacks.Add(function); return _FunctionStacks; }
public static Expr WrapStackTrace(Expr expr, CodeContext context, FunctionStack callSite) { var tempVar = Expr.Variable(typeof(object), "$metamethod_result$"); return Expr.Block(new[] { tempVar }, LuaExpr.FunctionScope(context, callSite.ExecScope, callSite.UpScope, new[] { callSite.Identifier }, Expr.Assign(tempVar, expr))); }
internal static Expr PushFunctionStack(CodeContext context, FunctionStack function) { return CallBackingMethod("_PushFunctionStack", context, Expr.Constant(function)); }
public static Expr WrapStackTrace(Expr expr, LuaTable parentTable, FunctionStack callSite) { var tempVar = Expr.Variable(typeof(object), "$metamethod_result$"); var context = Expr.Property(Expr.Constant(parentTable), "Context"); return Expr.Block(new [] { tempVar }, LuaExpr.FunctionScope(context, callSite.Identifier, Expr.Assign(tempVar, expr))); }