Exemple #1
0
 public FunctionCallExpression(Parser yyp, FunctionCall fc)
     : base(((LSLSyntax
         )yyp))
 {
     kids.Add(fc);
 }
Exemple #2
0
 public Statement(Parser yyp, FunctionCall fc)
     : base(((LSLSyntax
         )yyp))
 {
     kids.Add(fc);
 }
        /// <summary>
        /// Generates the code for a FunctionCall node.
        /// </summary>
        /// <param name="fc">The FunctionCall node.</param>
        /// <returns>String containing C# code for FunctionCall fc.</returns>
        private string GenerateFunctionCall(FunctionCall fc)
        {
            string retstr = String.Empty;

            string fname = CheckName(fc.Id);

            ApiMethod apiMethod;
            if (m_scene.TryGetApiMethod(fname, out apiMethod))
            {
                if (apiMethod.MethodInfo.ReturnType != typeof(void))
                {
                    string nativeType = apiMethod.MethodInfo.ReturnType.Name;
                    retstr += "(" + NativeTypeToLSLType(nativeType) + ")(" + nativeType + ")";
                }

                retstr += Generate("m_scriptWrapper.CallApiMethod(\"" + fname + "\"", fc);

                if (fc.kids.Count == 1)
                {
                    ArgumentList al = (ArgumentList)fc.kids[0];
                    ParameterInfo[] parameters = apiMethod.MethodInfo.GetParameters();

                    // Tells us whether to print a comma
                    int comma = al.kids.Count - 1;

                    // One or more function args, build a "new object[] { }" containing them
                    retstr += ", new object[] {";

                    if (al.kids.Count == parameters.Length - 1)
                    {
                        for (int i = 0; i < al.kids.Count; i++)
                        {
                            SYMBOL kid = (SYMBOL)al.kids[i];
                            ParameterInfo parameter = parameters[i + 1];

                            // Typecast
                            retstr += "(" + parameter.ParameterType.Name + ")";

                            retstr += "(";
                            retstr += GenerateNode(kid);
                            retstr += ")";

                            if (0 < comma--)
                                retstr += Generate(", ");
                        }
                    }
                    else
                    {
                        AddWarning("Incorrect number of parameters passed to " + fname + ", expecting " + parameters.Length);
                    }

                    retstr += "}";
                }
            }
            else
            {
                retstr += Generate(fname + "(", fc);

                foreach (SYMBOL kid in fc.kids)
                    retstr += GenerateNode(kid);
            }

            retstr += Generate(")");

            return retstr;
        }