private static void ParseLamdaDefinitionArgList(LambdaScope scope, List<ParameterExpression> parameters) { ParameterExpression paramArgList = scope.RegisterParameter(typeof(object[]), csArgListP); ParameterExpression varArgList = scope.RegisterVariable(typeof(LuaResult), csArgList); parameters.Add(paramArgList); scope.AddExpression(Expression.Assign(varArgList, Expression.New(Lua.ResultConstructorInfoArgN, paramArgList))); }
private static Expression ParseLamdaDefinition(Scope parent, LuaLexer code, string sName, bool lSelfParameter, Action<Type> functionTypeCollected) { List<ParameterExpression> parameters = new List<ParameterExpression>(); LambdaScope scope = new LambdaScope(parent); // Lese die Parameterliste ein FetchToken(LuaToken.BracketOpen, code); if (lSelfParameter) parameters.Add(scope.RegisterParameter(typeof(object), "self")); if (code.Current.Typ == LuaToken.Identifier || code.Current.Typ == LuaToken.DotDotDot) { if (code.Current.Typ == LuaToken.DotDotDot) { code.Next(); ParseLamdaDefinitionArgList(scope, parameters); } else { Token tName; Type typeArgument; ParseIdentifierAndType(scope, code, out tName, out typeArgument); parameters.Add(scope.RegisterParameter(typeArgument, tName.Value)); while (code.Current.Typ == LuaToken.Comma) { code.Next(); if (code.Current.Typ == LuaToken.DotDotDot) { code.Next(); ParseLamdaDefinitionArgList(scope, parameters); // last argument break; } else { ParseIdentifierAndType(scope, code, out tName, out typeArgument); parameters.Add(scope.RegisterParameter(typeArgument, tName.Value)); } } } } FetchToken(LuaToken.BracketClose, code); // Is there a specific result if (code.Current.Typ == LuaToken.Colon) { var t = code.Current; code.Next(); Type typeResult = ParseType(scope, code, true); scope.ResetReturnLabel(typeResult, null); } else scope.ResetReturnLabel(typeof(LuaResult), Expression.Property(null, Lua.ResultEmptyPropertyInfo)); // register the delegate if (functionTypeCollected != null) { functionTypeCollected( Expression.GetFuncType( (from p in parameters select p.Type).Concat(new Type[] { scope.ReturnType }).ToArray() ) ); } // Lese den Code-Block ParseBlock(scope, code); FetchToken(LuaToken.KwEnd, code); return Expression.Lambda( scope.ExpressionBlock, (parent.EmitDebug & LuaDebugLevel.RegisterMethods) == LuaDebugLevel.RegisterMethods ? Lua.RegisterUniqueName(sName) : sName, parameters); }