Exemple #1
0
    void MakeEqual()
    {
        m_szTempBuilder.Length = 0;
        StringBuilder fileData = m_szTempBuilder;

        fileData.AppendLine("    [MonoPInvokeCallbackAttribute(typeof(FCLibHelper.fc_call_back_inport_class_equal))]");
        fileData.AppendLine("    public static bool  obj_equal(long L, long R)");
        fileData.AppendLine("    {");
        fileData.AppendFormat("        {0} left  = FCGetObj.GetObj<{0}>(L);\r\n", m_szCurClassName, m_szCurClassName);
        fileData.AppendFormat("        {0} right = FCGetObj.GetObj<{0}>(R);\r\n", m_szCurClassName, m_szCurClassName);
        fileData.AppendLine("        if(left != null)");
        fileData.AppendLine("        {");
        fileData.AppendLine("            return left.Equals(right);");
        fileData.AppendLine("        }");
        fileData.AppendLine("        if(right != null)");
        fileData.AppendLine("        {");
        fileData.AppendLine("            return right.Equals(left);");
        fileData.AppendLine("        }");
        fileData.AppendLine("        return true;");
        fileData.AppendLine("    }");

        WrapFuncDesc func = new WrapFuncDesc();

        func.m_szName     = func.m_szGetName = func.m_szSetName = "obj_equal";
        func.m_bAttrib    = false;
        func.m_szContent  = fileData.ToString();
        func.m_szRegister = "FCLibHelper.fc_register_class_equal(nClassName,obj_equal);";
        m_CurClassFunc.Insert(0, func);
    }
Exemple #2
0
    void MakeInitFunc(string szClassName)
    {
        m_szTempBuilder.Length = 0;
        StringBuilder fileData = m_szTempBuilder;

        fileData.AppendLine("    public static void Register()");
        fileData.AppendLine("    {");
        fileData.AppendFormat("        int nClassName = FCLibHelper.fc_get_inport_class_id(\"{0}\");\r\n", szClassName);
        foreach (WrapFuncDesc func in m_CurClassFunc)
        {
            if (string.IsNullOrEmpty(func.m_szRegister))
            {
                continue;
            }
            fileData.AppendFormat("        {0}\r\n", func.m_szRegister);
        }
        fileData.AppendLine("    }");

        WrapFuncDesc init_func = new WrapFuncDesc();

        init_func.m_szName    = init_func.m_szGetName = init_func.m_szSetName = "Register";
        init_func.m_bAttrib   = false;
        init_func.m_szContent = fileData.ToString();
        m_CurClassFunc.Insert(0, init_func);
    }
Exemple #3
0
    void MakeGetObj()
    {
        m_szTempBuilder.Length = 0;
        StringBuilder fileData = m_szTempBuilder;

        fileData.AppendFormat("    public static {0} get_obj(long L)\r\n", m_szCurClassName);
        fileData.AppendLine("    {");
        fileData.AppendFormat("        return FCGetObj.GetObj<{0}>(L);\r\n", m_szCurClassName);
        fileData.AppendLine("    }");

        WrapFuncDesc init_func = new WrapFuncDesc();

        init_func.m_szName    = init_func.m_szGetName = init_func.m_szSetName = "get_obj";
        init_func.m_bAttrib   = false;
        init_func.m_szContent = fileData.ToString();
        m_CurClassFunc.Insert(0, init_func);
    }
Exemple #4
0
    void MakeReleaseRef()
    {
        m_szTempBuilder.Length = 0;
        StringBuilder fileData = m_szTempBuilder;

        fileData.AppendLine("    [MonoPInvokeCallbackAttribute(typeof(FCLibHelper.fc_call_back_inport_class_func))]");
        fileData.AppendLine("    public static int  obj_release(long L)");
        fileData.AppendLine("    {");
        fileData.AppendLine("        FCGetObj.ReleaseRef(L);");
        fileData.AppendLine("        return 0;");
        fileData.AppendLine("    }");

        WrapFuncDesc func = new WrapFuncDesc();

        func.m_szName     = func.m_szGetName = func.m_szSetName = "obj_release";
        func.m_bAttrib    = false;
        func.m_szContent  = fileData.ToString();
        func.m_szRegister = "FCLibHelper.fc_register_class_release_ref(nClassName,obj_release);";
        m_CurClassFunc.Insert(0, func);
    }
Exemple #5
0
    void MakeDefNew()
    {
        m_szTempBuilder.Length = 0;
        StringBuilder fileData = m_szTempBuilder;

        fileData.AppendLine("    [MonoPInvokeCallbackAttribute(typeof(FCLibHelper.fc_call_back_inport_class_func))]");
        fileData.AppendLine("    public static int  obj_new(long L)");
        fileData.AppendLine("    {");
        fileData.AppendFormat("        long nPtr = FCGetObj.NewObj<{0}>();\r\n", m_szCurClassName);
        fileData.AppendLine("        long ret = FCLibHelper.fc_get_return_ptr(L);");
        fileData.AppendLine("        FCLibHelper.fc_set_value_intptr(ret, nPtr);");
        fileData.AppendLine("        return 0;");
        fileData.AppendLine("    }");

        WrapFuncDesc func = new WrapFuncDesc();

        func.m_szName     = func.m_szGetName = func.m_szSetName = "obj_new";
        func.m_bAttrib    = false;
        func.m_szContent  = fileData.ToString();
        func.m_szRegister = "FCLibHelper.fc_register_class_new(nClassName, obj_new);";
        m_CurClassFunc.Insert(0, func);
    }
Exemple #6
0
    void MakeHash()
    {
        m_szTempBuilder.Length = 0;
        StringBuilder fileData = m_szTempBuilder;

        fileData.AppendLine("    [MonoPInvokeCallbackAttribute(typeof(FCLibHelper.fc_call_back_inport_class_func))]");
        fileData.AppendLine("    public static int  obj_hash(long L)");
        fileData.AppendLine("    {");
        fileData.AppendFormat("        {0} obj = FCGetObj.GetObj<{0}>(L);\r\n", m_szCurClassName, m_szCurClassName);
        fileData.AppendLine("        if(obj != null)");
        fileData.AppendLine("        {");
        fileData.AppendLine("            return obj.GetHashCode();");
        fileData.AppendLine("        }");
        fileData.AppendLine("        return 0;");
        fileData.AppendLine("    }");

        WrapFuncDesc func = new WrapFuncDesc();

        func.m_szName     = func.m_szGetName = func.m_szSetName = "obj_hash";
        func.m_bAttrib    = false;
        func.m_szContent  = fileData.ToString();
        func.m_szRegister = "FCLibHelper.fc_register_class_hash(nClassName,obj_hash);";
        m_CurClassFunc.Insert(0, func);
    }
Exemple #7
0
    // 功能:添加函数调用的方法
    void PushMethodInfo(MethodInfo method)
    {
        if (0 != (MethodAttributes.SpecialName & method.Attributes))
        {
            return;
        }
        if (m_bPartWrap)
        {
            if (!method.IsDefined(typeof(PartWrapAttribute), false))
            {
                return;
            }
        }
        // 如果该函数有不导出的标记
        if (method.IsDefined(typeof(DontWrapAttribute), false))
        {
            return;
        }
        if (method.IsDefined(typeof(ObsoleteAttribute), false))
        {
            return;
        }
        string szMethodName  = method.ToString();
        bool   bTemplateFunc = IsTemplateFunc(method);

        // 模板函数暂时不导出吧
        if (bTemplateFunc)
        {
            return;
        }
        FCValueType ret_value = m_templateWrap.PushReturnTypeWrap(method.ReturnType);

        PushNameSpace(method.ReturnType.Namespace);

        int nSameNameCount = 0;

        if (m_CurSameName.TryGetValue(method.Name, out nSameNameCount))
        {
        }
        m_CurSameName[method.Name] = nSameNameCount + 1;
        int nFuncCount = 0;

        m_CurFuncCount.TryGetValue(method.Name, out nFuncCount);

        WrapFuncDesc func = new WrapFuncDesc();

        func.m_bAttrib = false;
        func.m_szName  = method.Name;
        if (nSameNameCount > 0)
        {
            func.m_szGetName = func.m_szSetName = string.Format("{0}{1}_wrap", method.Name, nSameNameCount);
        }
        else
        {
            func.m_szGetName = func.m_szSetName = string.Format("{0}_wrap", method.Name);
        }

        m_szTempBuilder.Length = 0;
        StringBuilder fileData = m_szTempBuilder;

        ParameterInfo[] allParams   = method.GetParameters(); // 函数参数
        Type            nRetType    = method.ReturnType;      // 返回值
        int             nParamCount = allParams != null ? allParams.Length : 0;
        bool            bEqualFunc  = func.m_szName == "Equals";

        fileData.AppendLine("    [MonoPInvokeCallbackAttribute(typeof(FCLibHelper.fc_call_back_inport_class_func))]");
        fileData.AppendFormat("    public static int {0}(long L)\r\n", func.m_szSetName);
        fileData.AppendLine("    {");
        fileData.AppendLine("        try");
        fileData.AppendLine("        {");

        fileData.AppendLine("            long nThisPtr = FCLibHelper.fc_get_inport_obj_ptr(L);");
        fileData.AppendFormat("            {0} obj = get_obj(nThisPtr);\r\n", m_szCurClassName);
        // 处理函数参数
        Type   nParamType;
        string szLeftName     = string.Empty;
        string szCallParam    = string.Empty;
        string szLeftType     = string.Empty;
        bool   bStatic        = method.IsStatic;
        string szFullFuncName = method.Name;

        for (int i = 0; i < nParamCount; ++i)
        {
            ParameterInfo param = allParams[i];
            nParamType = param.ParameterType;
            szLeftName = string.Format("arg{0}", i);
            PushNameSpace(nParamType.Namespace);
            FCValueType param_value = FCTemplateWrap.Instance.PushGetTypeWrap(nParamType);
            if (param.IsOut)
            {
                string szCSharpName = param_value.GetTypeName(true);
                fileData.AppendFormat("            {0} {1};\r\n", szCSharpName, szLeftName);
            }
            else
            {
                SetMemberValue(fileData, "            ", param_value, szLeftName, "L", i.ToString(), true, param.IsOut);
            }
            if (i > 0)
            {
                szCallParam += ',';
            }
            if (param.IsOut)
            {
                szCallParam += "out ";
            }
            else if (nParamType.IsByRef)
            {
                szCallParam += "ref ";
            }
            szCallParam   += szLeftName;
            szFullFuncName = szFullFuncName + '_' + param_value.GetTypeName(false);
        }
        // 处理返回值
        if (ret_value.m_nValueType == fc_value_type.fc_value_void)
        {
            if (bStatic)
            {
                fileData.AppendFormat("            {0}.{1}({2});\r\n", m_szCurClassName, func.m_szName, szCallParam);
            }
            else
            {
                fileData.AppendFormat("            obj.{0}({1});\r\n", func.m_szName, szCallParam);
            }
        }
        else
        {
            string szCShareRetName = ret_value.GetTypeName(true);
            if (bStatic)
            {
                fileData.AppendFormat("            {0} ret = {1}.{2}({3});\r\n", szCShareRetName, m_szCurClassName, func.m_szName, szCallParam);
            }
            else
            {
                fileData.AppendFormat("            {0} ret = obj.{1}({2});\r\n", szCShareRetName, func.m_szName, szCallParam);
            }
        }

        // 处理输出参数
        for (int i = 0; i < nParamCount; ++i)
        {
            ParameterInfo param = allParams[i];
            nParamType = param.ParameterType;
            szLeftName = string.Format("arg{0}", i);
            if (param.IsOut || nParamType.IsByRef)
            {
                FCValueType value = PushOutParamWrap(nParamType);
                fileData.Append(FCValueType.ModifyScriptCallParam("            ", value, szLeftName, "L", i.ToString(), true));
            }
        }
        // 处理返回值
        if (ret_value.m_nValueType != fc_value_type.fc_value_void)
        {
            FCValueType.PushReturnValue(fileData, "            ", ret_value, "L", "ret", false);
        }
        fileData.AppendLine("        }");
        fileData.AppendLine("        catch(Exception e)");
        fileData.AppendLine("        {");
        fileData.AppendLine("            Debug.LogException(e);");
        fileData.AppendLine("        }");
        fileData.AppendLine("        return 0;");
        fileData.AppendLine("    }");

        func.m_szContent = fileData.ToString();
        if (nFuncCount > 1)
        {
            func.m_szRegister = string.Format("FCLibHelper.fc_register_class_func(nClassName,\"{0}\",{1});", szFullFuncName, func.m_szGetName);
        }
        else
        {
            func.m_szRegister = string.Format("FCLibHelper.fc_register_class_func(nClassName,\"{0}\",{1});", func.m_szName, func.m_szGetName);
        }
        m_CurClassFunc.Add(func);
    }
Exemple #8
0
    void  PushPropertyFunc(Type nVaueType, string szName, bool bCanGet, bool bCanSet, bool bStatic)
    {
        WrapFuncDesc func = new WrapFuncDesc();

        func.m_bAttrib = true;
        func.m_szName  = szName;
        if (bCanGet)
        {
            func.m_szGetName = string.Format("get_{0}_wrap", szName);
        }
        else
        {
            func.m_szGetName = "null";
        }
        if (bCanSet)
        {
            func.m_szSetName = string.Format("set_{0}_wrap", szName);
        }
        else
        {
            func.m_szSetName = "null";
        }

        FCValueType ret_value = FCTemplateWrap.Instance.PushGetTypeWrap(nVaueType);

        m_szTempBuilder.Length = 0;
        StringBuilder fileData   = m_szTempBuilder;
        string        szLeftName = string.Format("ret.{0}", szName);

        if (bStatic)
        {
            szLeftName = string.Format("{0}.{1}", m_szCurClassName, szName);
        }
        if (bCanGet)
        {
            m_templateWrap.PushReturnTypeWrap(nVaueType);

            fileData.AppendLine("    [MonoPInvokeCallbackAttribute(typeof(FCLibHelper.fc_call_back_inport_class_func))]");
            fileData.AppendFormat("    public static int {0}(long L)\r\n", func.m_szGetName);
            fileData.AppendLine("    {");
            fileData.AppendLine("        try");
            fileData.AppendLine("        {");
            fileData.AppendLine("            long nThisPtr = FCLibHelper.fc_get_inport_obj_ptr(L);");
            fileData.AppendFormat("            {0} ret = get_obj(nThisPtr);\r\n", m_szCurClassName);
            FCValueType.PushReturnValue(fileData, "            ", ret_value, "L", szLeftName, true);
            fileData.AppendLine("        }");
            fileData.AppendLine("        catch(Exception e)");
            fileData.AppendLine("        {");
            fileData.AppendLine("            Debug.LogException(e);");
            fileData.AppendLine("        }");
            fileData.AppendLine("        return 0;");
            fileData.AppendLine("    }");
        }

        if (bCanSet)
        {
            fileData.AppendLine("    [MonoPInvokeCallbackAttribute(typeof(FCLibHelper.fc_call_back_inport_class_func))]");
            fileData.AppendFormat("    public static int {0}(long L)\r\n", func.m_szSetName);
            fileData.AppendLine("    {");
            fileData.AppendLine("        try");
            fileData.AppendLine("        {");
            fileData.AppendLine("            long nThisPtr = FCLibHelper.fc_get_inport_obj_ptr(L);");
            fileData.AppendFormat("            {0} ret = get_obj(nThisPtr);\r\n", m_szCurClassName);
            SetMemberValue(fileData, "            ", ret_value, "arg0", "L", "0", true, false);
            fileData.AppendFormat("            {0} = arg0;\r\n", szLeftName);
            fileData.AppendLine("        }");
            fileData.AppendLine("        catch(Exception e)");
            fileData.AppendLine("        {");
            fileData.AppendLine("            Debug.LogException(e);");
            fileData.AppendLine("        }");
            fileData.AppendLine("        return 0;");
            fileData.AppendLine("    }");
        }
        func.m_szContent  = fileData.ToString();
        func.m_szRegister = string.Format("FCLibHelper.fc_register_class_attrib(nClassName,\"{0}\",{1},{2});", func.m_szName, func.m_szGetName, func.m_szSetName);
        m_CurClassFunc.Add(func);
    }
Exemple #9
0
    void PushPropertyDelegate(FCValueType ret_value, string szName, bool bCanGet, bool bCanSet, bool bStatic)
    {
        WrapFuncDesc func = new WrapFuncDesc();

        func.m_bAttrib = true;
        func.m_szName  = szName;
        if (bCanGet)
        {
            func.m_szGetName = string.Format("get_{0}_wrap", szName);
        }
        else
        {
            func.m_szGetName = "null";
        }
        if (bCanSet)
        {
            func.m_szSetName = string.Format("set_{0}_wrap", szName);
        }
        else
        {
            func.m_szSetName = "null";
        }

        m_szTempBuilder.Length = 0;
        StringBuilder fileData   = m_szTempBuilder;
        string        szLeftName = string.Format("ret.{0}", szName);

        if (bStatic)
        {
            szLeftName = string.Format("{0}.{1}", m_szCurClassName, szName);
        }

        string szDelegateClassName = string.Format("{0}_deletate", ret_value.GetDelegateName(true));

        m_deleteWrap.PushDelegateWrap(ret_value.m_value, szDelegateClassName);

        if (bCanSet)
        {
            fileData.AppendLine("    [MonoPInvokeCallbackAttribute(typeof(FCLibHelper.fc_call_back_inport_class_func))]");
            fileData.AppendFormat("    public static int {0}(long L)\r\n", func.m_szSetName);
            fileData.AppendLine("    {");
            fileData.AppendLine("        try");
            fileData.AppendLine("        {");

            fileData.AppendFormat("            {0} func = FCDelegateMng.Instance.GetDelegate<{1}>(L);\r\n", szDelegateClassName, szDelegateClassName);
            if (bStatic)
            {
                fileData.AppendLine("            if(func != null)");
                fileData.AppendFormat("                {0} = func.CallFunc;\r\n", szLeftName);
                fileData.AppendLine("            else");
                fileData.AppendFormat("                {0} = null;\r\n", szLeftName);
            }
            else
            {
                fileData.AppendLine("            long nThisPtr = FCLibHelper.fc_get_inport_obj_ptr(L);");
                fileData.AppendFormat("            {0} ret = get_obj(nThisPtr);\r\n", m_szCurClassName);
                fileData.AppendLine("            if(func != null)");
                fileData.AppendFormat("                {0} = func.CallFunc;\r\n", szLeftName);
                fileData.AppendLine("            else");
                fileData.AppendFormat("                {0} = null;\r\n", szLeftName);
            }
            fileData.AppendFormat("            FCDelegateMng.Instance.RecordDelegate({0}, func);\r\n", szLeftName);
            fileData.AppendLine("        }");
            fileData.AppendLine("        catch(Exception e)");
            fileData.AppendLine("        {");
            fileData.AppendLine("            Debug.LogException(e);");
            fileData.AppendLine("        }");
            fileData.AppendLine("        return 0;");
            fileData.AppendLine("    }");
        }
        func.m_szContent  = fileData.ToString();
        func.m_szRegister = string.Format("FCLibHelper.fc_register_class_attrib(nClassName,\"{0}\",{1},{2});", func.m_szName, func.m_szGetName, func.m_szSetName);
        m_CurClassFunc.Add(func);
    }
Exemple #10
0
    void MakeParamNew(ConstructorInfo conInfo, int nFuncIndex)
    {
        ParameterInfo[] allParams = conInfo.GetParameters();
        if (allParams == null || allParams.Length == 0)
        {
            MakeDefNew();
            return;
        }

        m_szTempBuilder.Length = 0;
        StringBuilder fileData = m_szTempBuilder;

        fileData.AppendLine("    [MonoPInvokeCallbackAttribute(typeof(FCLibHelper.fc_call_back_inport_class_func))]");
        fileData.AppendFormat("    public static int  obj_new{0}(long L)\r\n", nFuncIndex);
        fileData.AppendLine("    {");
        fileData.AppendLine("        try");
        fileData.AppendLine("        {");
        string szCallParam = string.Empty;
        Type   nParamType;
        string szLeftName = string.Empty;

        for (int i = 0; i < allParams.Length; ++i)
        {
            ParameterInfo param = allParams[i];
            nParamType = param.ParameterType;

            FCValueType param_value = FCTemplateWrap.Instance.PushGetTypeWrap(nParamType);

            szLeftName = string.Format("arg{0}", i);
            if (param.IsOut)
            {
                string szCSharpName = param_value.GetTypeName(true);
                fileData.AppendFormat("            {0} {1};\r\n", szCSharpName, szLeftName);
            }
            else
            {
                SetMemberValue(fileData, "            ", param_value, szLeftName, "L", i.ToString(), true, param.IsOut);
            }
            if (i > 0)
            {
                szCallParam += ',';
            }
            if (param.IsOut)
            {
                szCallParam += "out ";
            }
            else if (nParamType.IsByRef)
            {
                szCallParam += "ref ";
            }
            szCallParam += szLeftName;
        }
        fileData.AppendFormat("            {0} obj = new {1}({2});\r\n", m_szCurClassName, m_szCurClassName, szCallParam);
        fileData.AppendFormat("            long nPtr = FCGetObj.PushNewObj<{0}>(obj);\r\n", m_szCurClassName);
        fileData.AppendLine("            long ret = FCLibHelper.fc_get_return_ptr(L);");
        fileData.AppendLine("            FCLibHelper.fc_set_value_intptr(ret, nPtr);");
        fileData.AppendLine("        }");
        fileData.AppendLine("        catch(Exception e)");
        fileData.AppendLine("        {");
        fileData.AppendLine("            Debug.LogException(e);");
        fileData.AppendLine("        }");
        fileData.AppendLine("        return 0;");
        fileData.AppendLine("    }");

        WrapFuncDesc func = new WrapFuncDesc();

        func.m_szName     = m_szCurClassName;
        func.m_szGetName  = func.m_szSetName = string.Format("obj_new{0}", nFuncIndex);
        func.m_bAttrib    = false;
        func.m_szContent  = fileData.ToString();
        func.m_szRegister = string.Format("FCLibHelper.fc_register_class_func(nClassName, \"{0}\", {1});", m_szCurClassName, func.m_szGetName);
        m_CurClassFunc.Insert(0, func);
    }