/// <summary>
        ///     Invokes a export function from a given script.
        /// </summary>
        /// <param name="symbol">Symbol of function to call.</param>
        /// <param name="toThread">Thread to call function.</param>
        /// <param name="fromThread">Thread to call function from.</param>
        /// <returns>Memory index of new array.</returns>
        public void InvokeExportFunction(FunctionSymbol symbol, ScriptThread toThread, ScriptThread fromThread)
        {
            // Can't invoke functions if debugging :S.
            if (_debugger != null && _debugger.AllowInvokedFunctions == false && toThread == this)
                return;

            // Find the functions parameter types.
            DataTypeValue[] parameterTypes = new DataTypeValue[symbol.ParameterCount];
            for (int i = 0; i < symbol.ParameterCount; i++)
                parameterTypes[i] = ((VariableSymbol)symbol.Symbols[i]).DataType;

            // Push any parameters we have been given.
            for (int i = 0; i < parameterTypes.Length; i++)
            {
                RuntimeValue parameter = fromThread._runtimeStack[(fromThread._runtimeStack.TopIndex - parameterTypes.Length) + i];
                parameter.DataType = parameterTypes[i];

                if (parameterTypes[i].IsArray == true)
                    toThread.PassParameterArray(CopyValueArrayFromThread(parameter, toThread, fromThread));
                else
                    toThread.PassParameter(CopyValueFromThread(parameter, toThread, fromThread));
            }

            // Call the function.
            toThread.InvokeFunction(symbol.Identifier, true, true);

            // Copy the return register.
            fromThread._registers[(int)Register.Return].DataType = symbol.ReturnType;
            if (symbol.ReturnType.IsArray == true)
                SetMemoryIndexValue(fromThread._registers[(int)Register.Return], CopyValueArrayFromThread(toThread._registers[(int)Register.Return], fromThread, toThread));
            else
                fromThread._registers[(int)Register.Return] = CopyValueFromThread(toThread._registers[(int)Register.Return], fromThread, toThread);
        }