本文整理汇总了C#中Generator.CompileInline方法的典型用法代码示例。如果您正苦于以下问题:C# Generator.CompileInline方法的具体用法?C# Generator.CompileInline怎么用?C# Generator.CompileInline使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Generator
的用法示例。
在下文中一共展示了Generator.CompileInline方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CompileString
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();
}
示例2: CompileString
static Func<dynamic> CompileString(LuaContext context, string source)
{
ContractUtils.RequiresNotNull(context, "context");
var sourceUnit = context.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 expr = gen.CompileInline(ast, context.Trace.CurrentEvaluationScope.GetRoot(), context.Trace.CurrentScopeStorage, sourceUnit);
return expr.Compile();
}