Example #1
0
        /// <summary>
        /// Compiles a function with a specified parameters and body and adds it to dynamic module.
        /// </summary>
        /// <param name="parameters">The function's parameters (e.g. <c>"$x, $y = 1, &amp;$z"</c>).</param>
        /// <param name="body">The function's body.</param>
        /// <param name="context">A script context.</param>
        /// <param name="descriptor"></param>
        /// <returns>A name of the created function.</returns>
        /// <exception cref="ArgumentNullException">Any parameter is a <B>null</B> reference.</exception>
        public static string CreateLambdaFunction(string /*!*/ parameters, string /*!*/ body, ScriptContext /*!*/ context,
                                                  SourceCodeDescriptor descriptor)
        {
            if (parameters == null)
            {
                throw new ArgumentNullException("parameters");
            }
            if (body == null)
            {
                throw new ArgumentNullException("body");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            string name = GenerateLambdaName(parameters, body);

            if (context.DeclaredFunctions != null && context.DeclaredFunctions.ContainsKey(name))
            {
                return(name);
            }

            string prefix1, prefix2;

            GetLamdaFunctionCodePrefixes(name, parameters, out prefix1, out prefix2);

            context.ClearCapturedSourceCodeDescriptor();
            EvalInternal(prefix2, body, "}", EvalKinds.LambdaFunction, context, null, null, null, descriptor, false, null);             // TODO: naming context in lambda function??

            return(name);
        }
Example #2
0
		/// <summary>
		/// Compiles a function with a specified parameters and body and adds it to dynamic module. 
		/// </summary>
		/// <param name="parameters">The function's parameters (e.g. <c>"$x, $y = 1, &amp;$z"</c>).</param>
		/// <param name="body">The function's body.</param>
		/// <param name="context">A script context.</param>
		/// <param name="descriptor"></param>
		/// <returns>A name of the created function.</returns>
		/// <exception cref="ArgumentNullException">Any parameter is a <B>null</B> reference.</exception>
		public static string CreateLambdaFunction(string/*!*/ parameters, string/*!*/ body, ScriptContext/*!*/ context,
			SourceCodeDescriptor descriptor)
		{
			if (parameters == null)
				throw new ArgumentNullException("parameters");
			if (body == null)
				throw new ArgumentNullException("body");
			if (context == null)
				throw new ArgumentNullException("context");

			string name = GenerateLambdaName(parameters, body);
            if (context.DeclaredFunctions != null && context.DeclaredFunctions.ContainsKey(name))
                return name;

			string prefix1, prefix2;
			GetLamdaFunctionCodePrefixes(name, parameters, out prefix1, out prefix2);

			context.ClearCapturedSourceCodeDescriptor();
			EvalInternal(prefix2, body, "}", EvalKinds.LambdaFunction, context, null, null, null, descriptor, false, null); // TODO: naming context in lambda function??

			return name;
		}