示例#1
0
        /// <summary>
        /// Adds a TFunction to the function dictionary.
        /// </summary>
        /// <param name="interpreter">The interpreter that the method is being called from.</param>
        /// <param name="function">The TFunction to be added to the function dictionary.</param>
        /// <returns>Null if the operation was successful, otherwise a TException.</returns>
        public static TException AddFunction(Interpreter interpreter, TFunction function)
        {
            if (function == null)
            {
                return(new TException(interpreter, "Null TFunction given"));
            }

            // Reject the function if it's already in the standard library
            TFunction existingFunction = StdLibrary.GetFunction(function.Name);

            if (existingFunction != null)
            {
                return(new TException(interpreter,
                                      "Standard library function with name '" + function.Name + "' already exists"));
            }

            // Add it to the function dictionary, overwriting another function with the same name if neccessary
            existingFunction = GetFunction(function.Name, false);
            if (existingFunction == null)
            {
                functions.Add(function.Name, function);
            }
            else
            {
                existingFunction.HardCodedFunction = null;
                existingFunction.CustomFunction    = "";
                existingFunction.Block             = null;
                existingFunction.CopyFrom(function);
            }

            return(null);
        }
示例#2
0
        /// <summary>
        /// Searches for a Toast function with the specified name.
        /// </summary>
        /// <param name="functionName">The name of the Toast function to seach for.</param>
        /// <param name="includeStdLibrary">Whether the Toast standard library should be searched.</param>
        /// <returns>A TFunction if the operation was successful, otherwise null.</returns>
        public static TFunction GetFunction(string functionName, bool includeStdLibrary = true)
        {
            TFunction returnValue;

            if (functions.TryGetValue(functionName, out returnValue))
            {
                return(returnValue);
            }
            return(includeStdLibrary ? StdLibrary.GetFunction(functionName) : null);
        }