Exemplo n.º 1
0
        private void WriteFunction(FunctionData function)
        {
            string paramString = string.Empty;
            string overrideString;
            string returnTypeString;
            string functionContentString;

            switch (m_ScriptPrescription.m_Lang)
            {
            case Language.JavaScript:
                // Comment
                WriteComment(function.comment);

                // Function header
                for (int i = 0; i < function.parameters.Length; i++)
                {
                    paramString += function.parameters[i].name + " : " + TranslateTypeToJavascript(function.parameters[i].type);
                    if (i < function.parameters.Length - 1)
                    {
                        paramString += ", ";
                    }
                }
                overrideString   = (function.isVirtual ? "override " : string.Empty);
                returnTypeString = (function.returnType == null ? " " : " : " + TranslateTypeToJavascript(function.returnType) + " ");
                m_Writer.WriteLine(m_Indentation + overrideString + "function " + function.name + " (" + paramString + ")" + returnTypeString + "{");

                // Function content
                IndentLevel++;
                functionContentString = (function.returnType == null ? string.Empty : function.returnDefault + ";");
                m_Writer.WriteLine(m_Indentation + functionContentString);
                IndentLevel--;
                m_Writer.WriteLine(m_Indentation + "}");

                break;

            case Language.CSharp:
                // Comment
                WriteComment(function.comment);

                // Function header
                for (int i = 0; i < function.parameters.Length; i++)
                {
                    paramString += function.parameters[i].type + " " + function.parameters[i].name;
                    if (i < function.parameters.Length - 1)
                    {
                        paramString += ", ";
                    }
                }
                overrideString   = (function.isVirtual ? "public override " : string.Empty);
                returnTypeString = (function.returnType == null ? "void " : function.returnType + " ");
                m_Writer.WriteLine(m_Indentation + overrideString + returnTypeString + function.name + " (" + paramString + ") {");

                // Function content
                IndentLevel++;
                functionContentString = (function.returnType == null ? string.Empty : function.returnDefault + ";");
                m_Writer.WriteLine(m_Indentation + functionContentString);
                IndentLevel--;
                m_Writer.WriteLine(m_Indentation + "}");

                break;

            case Language.Boo:
                // Comment
                WriteComment(function.comment);

                // Function header
                for (int i = 0; i < function.parameters.Length; i++)
                {
                    paramString += function.parameters[i].name + " as " + TranslateTypeToBoo(function.parameters[i].type);
                    if (i < function.parameters.Length - 1)
                    {
                        paramString += ", ";
                    }
                }
                overrideString   = (function.isVirtual ? "public override " : string.Empty);
                returnTypeString = (function.returnType == null ? string.Empty : " as " + TranslateTypeToJavascript(function.returnType));
                m_Writer.WriteLine(m_Indentation + overrideString + "def " + function.name + " (" + paramString + ")" + returnTypeString + ":");

                // Function content
                IndentLevel++;
                functionContentString = (function.returnType == null ? "pass" : function.returnDefault);
                m_Writer.WriteLine(m_Indentation + functionContentString);
                IndentLevel--;

                break;
            }
        }
		private void WriteFunction (FunctionData function)
		{
			string paramString = string.Empty;
			string overrideString;
			string returnTypeString;
			string functionContentString;
			
			switch (m_ScriptPrescription.m_Lang)
			{
			case Language.JavaScript:
				// Comment
				WriteComment (function.comment);
				
				// Function header
				for (int i=0; i<function.parameters.Length; i++)
				{
					paramString += function.parameters[i].name + " : " + TranslateTypeToJavascript (function.parameters[i].type);
					if (i < function.parameters.Length-1)
						paramString += ", ";
				}
				overrideString = (function.isVirtual ? "override " : string.Empty);
				returnTypeString = (function.returnType == null ? " " : " : " + TranslateTypeToJavascript (function.returnType) + " ");
				m_Writer.WriteLine (m_Indentation + overrideString + "function " + function.name + " (" + paramString + ")" + returnTypeString + "{");
				
				// Function content
				IndentLevel++;
				functionContentString = (function.returnType == null ? string.Empty : function.returnDefault + ";");
				m_Writer.WriteLine (m_Indentation + functionContentString);
				IndentLevel--;
				m_Writer.WriteLine (m_Indentation + "}");
				
				break;
				
			case Language.CSharp:
				// Comment
				WriteComment (function.comment);
				
				// Function header
				for (int i=0; i<function.parameters.Length; i++)
				{
					paramString += function.parameters[i].type + " " + function.parameters[i].name;
					if (i < function.parameters.Length-1)
						paramString += ", ";
				}
				overrideString = (function.isVirtual ? "public override " : string.Empty);
				returnTypeString = (function.returnType == null ? "void " : function.returnType + " ");
				m_Writer.WriteLine (m_Indentation + overrideString + returnTypeString + function.name + " (" + paramString + ") {");
				
				// Function content
				IndentLevel++;
				functionContentString = (function.returnType == null ? string.Empty : function.returnDefault + ";");
				m_Writer.WriteLine (m_Indentation + functionContentString);
				IndentLevel--;
				m_Writer.WriteLine (m_Indentation + "}");
				
				break;
				
			case Language.Boo:
				// Comment
				WriteComment (function.comment);
				
				// Function header
				for (int i=0; i<function.parameters.Length; i++)
				{
					paramString += function.parameters[i].name + " as " + TranslateTypeToBoo (function.parameters[i].type);
					if (i < function.parameters.Length-1)
						paramString += ", ";
				}
				overrideString = (function.isVirtual ? "public override " : string.Empty);
				returnTypeString = (function.returnType == null ? string.Empty : " as " + TranslateTypeToJavascript (function.returnType));
				m_Writer.WriteLine (m_Indentation + overrideString + "def " + function.name + " (" + paramString + ")" + returnTypeString + ":");
				
				// Function content
				IndentLevel++;
				functionContentString = (function.returnType == null ? "pass" : function.returnDefault);
				m_Writer.WriteLine (m_Indentation + functionContentString);
				IndentLevel--;
				
				break;
			}
		}