ConvertToLibSign() public static method

public static ConvertToLibSign ( string str ) : string
str string
return string
Ejemplo n.º 1
0
    static void GenRegisterInfo(string nameSpace, StringBuilder sb, List <DelegateType> delegateList, List <DelegateType> wrappedDelegatesCache)
    {
        for (int i = 0; i < allTypes.Count; i++)
        {
            Type dt = CustomSettings.dynamicList.Find((p) => { return(allTypes[i].type == p); });

            if (dt == null && allTypes[i].nameSpace == nameSpace)
            {
                string str = "\t\t" + allTypes[i].wrapName + "Wrap.Register(L);\r\n";
                sb.Append(str);
                allTypes.RemoveAt(i--);
            }
        }

        string funcName = null;

        for (int i = 0; i < delegateList.Count; i++)
        {
            DelegateType dt        = delegateList[i];
            Type         type      = dt.type;
            string       typeSpace = ToLuaExport.GetNameSpace(type, out funcName);

            if (typeSpace == nameSpace)
            {
                funcName = ToLuaExport.ConvertToLibSign(funcName);
                string abr = dt.abr;
                abr = abr == null ? funcName : abr;
                sb.AppendFormat("\t\tL.RegFunction(\"{0}\", {1});\r\n", abr, dt.name);
                wrappedDelegatesCache.Add(dt);
            }
        }
    }
Ejemplo n.º 2
0
        public BindType(Type t)
        {
            //if (CustomSettings.staticClassTypes == null)
            //{
            //    Debug.LogError("\nCustomSettings.staticClassTypes is null ! ");
            //    return;
            //}

            if (t == null)
            {
                throw new NotSupportedException("\nBindType Type is null ! ");
            }

            if (typeof(System.MulticastDelegate).IsAssignableFrom(t))
            {
                throw new NotSupportedException(string.Format("\nDon't export Delegate {0} as a class, register it in customDelegateList", LuaMisc.GetTypeName(t)));
            }

            //if (IsObsolete(t))
            //{
            //    throw new Exception(string.Format("\n{0} is obsolete, don't export it!", LuaMisc.GetTypeName(t)));
            //}

            type      = t;
            nameSpace = ToLuaExport.GetNameSpace(t, out libName);
            name      = ToLuaExport.CombineTypeStr(nameSpace, libName);
            libName   = ToLuaExport.ConvertToLibSign(libName);

            if (name == "object")
            {
                wrapName = "System_Object";
                name     = "System.Object";
            }
            else if (name == "string")
            {
                wrapName = "System_String";
                name     = "System.String";
            }
            else
            {
                wrapName = name.Replace('.', '_');
                wrapName = ToLuaExport.ConvertToLibSign(wrapName);
            }

            if ((type.IsAbstract && type.IsSealed))
            {
                IsStatic = true;
            }

            baseType = LuaMisc.GetExportBaseType(type);
        }
Ejemplo n.º 3
0
        public BindType(Type t)
        {
            // 如果是委托及其衍生类,抛出异常
            if (typeof(System.MulticastDelegate).IsAssignableFrom(t))
            {
                throw new NotSupportedException(string.Format("\nDon't export Delegate {0} as a class, register it in customDelegateList", LuaMisc.GetTypeName(t)));
            }

            //if (IsObsolete(t))
            //{
            //    throw new Exception(string.Format("\n{0} is obsolete, don't export it!", LuaMisc.GetTypeName(t)));
            //}

            type = t;
            // 获取 type 的命名空间,并将 libName 更新为从完全限定名到命名空间后一位(也就是带'.'字符)的字符
            nameSpace = ToLuaExport.GetNameSpace(t, out libName);
            // 用"."字符拼接参数 space 与 name 为一个字符串并返回
            name = ToLuaExport.CombineTypeStr(nameSpace, libName);
            // 过滤、替换字符串中指定的字符并返回
            libName = ToLuaExport.ConvertToLibSign(libName);

            // 按规律设置 name 和 wrapName 的值
            if (name == "object")
            {
                wrapName = "System_Object";
                name     = "System.Object";
            }
            else if (name == "string")
            {
                wrapName = "System_String";
                name     = "System.String";
            }
            else
            {
                wrapName = name.Replace('.', '_');
                wrapName = ToLuaExport.ConvertToLibSign(wrapName);
            }

            // 获取 CustomSettings.staticClassTypes(静态类型)中 type 的 index
            int index = CustomSettings.staticClassTypes.IndexOf(type);

            // 如果大等于 0(代表没有这个类型)或 type 是虚类、密封类,设置 IsStatic 为真
            if (index >= 0 || (type.IsAbstract && type.IsSealed))
            {
                IsStatic = true;
            }

            // 获取导出文件的基类
            baseType = LuaMisc.GetExportBaseType(type);
        }
Ejemplo n.º 4
0
        public BindType(Type t)
        {
            if (typeof(System.MulticastDelegate).IsAssignableFrom(t))
            {
                string ex = string.Format("\nDon't export Delegate {0} as a class, register it in customDelegateList",
                                          LuaMisc.GetTypeName(t));
                throw new NotSupportedException(ex);
            }

            if (IsObsolete(t))
            {
                throw new Exception(string.Format("\n{0} is obsolete, don't export it!", LuaMisc.GetTypeName(t)));
            }

            type      = t;
            nameSpace = ToLuaExport.GetNameSpace(t, out libName);
            name      = ToLuaExport.CombineTypeStr(nameSpace, libName);
            libName   = ToLuaExport.ConvertToLibSign(libName);

            if (name == "object")
            {
                wrapName = "System_Object";
                name     = "System.Object";
            }
            else if (name == "string")
            {
                wrapName = "System_String";
                name     = "System.String";
            }
            else
            {
                wrapName = name.Replace('.', '_');
                wrapName = ToLuaExport.ConvertToLibSign(wrapName);
            }

            int index = CustomSettings.staticClassTypes.IndexOf(type);

            if (index >= 0 || (type.IsAbstract && type.IsSealed))
            {
                IsStatic = true;
            }

            baseType = LuaMisc.GetExportBaseType(type);
        }
Ejemplo n.º 5
0
        public BindType(Type t)
        {
            if (typeof(System.MulticastDelegate).IsAssignableFrom(t))
            {
                throw new NotSupportedException(string.Format("\nDon't export Delegate {0} as a class, register it in customDelegateList", LuaMisc.GetTypeName(t)));
            }

            type      = t;
            nameSpace = ToLuaExport.GetNameSpace(t, out libName);
            name      = ToLuaExport.CombineTypeStr(nameSpace, libName);
            libName   = ToLuaExport.ConvertToLibSign(libName);

            if (name == "object")
            {
                wrapName = "System_Object";
                name     = "System.Object";
            }
            else if (name == "string")
            {
                wrapName = "System_String";
                name     = "System.String";
            }
            else
            {
                wrapName = name.Replace('.', '_');
                wrapName = ToLuaExport.ConvertToLibSign(wrapName);
            }

            if (type.BaseType != null && type.BaseType != typeof(ValueType))
            {
                baseType = type.BaseType;
            }

            int index = CustomSettings.staticClassTypes.IndexOf(type);

            if (index >= 0 || (type.GetConstructor(Type.EmptyTypes) == null && type.IsAbstract && type.IsSealed))
            {
                IsStatic = true;
                baseType = baseType == typeof(object) ? null : baseType;
            }
        }
Ejemplo n.º 6
0
        public string nameSpace = null;     //注册到lua的table层级

        public BindType(Type t)
        {
            type      = t;
            nameSpace = ToLuaExport.GetNameSpace(t, out libName);
            name      = ToLuaExport.CombineTypeStr(nameSpace, libName);
            //nameSpace = ToLuaExport.ConvertToLibSign(nameSpace);
            libName = ToLuaExport.ConvertToLibSign(libName);

            if (name == "object")
            {
                wrapName = "System_Object";
                name     = "System.Object";
            }
            else if (name == "string")
            {
                wrapName = "System_String";
                name     = "System.String";
            }
            else
            {
                wrapName = name.Replace('.', '_');
                wrapName = ToLuaExport.ConvertToLibSign(wrapName);
            }

            if (t.BaseType != null && t.BaseType != typeof(ValueType))
            {
                baseType = t.BaseType;
            }

            int index = CustomSettings.staticClassTypes.IndexOf(t);

            if (index >= 0 || (t.GetConstructor(Type.EmptyTypes) == null && t.IsAbstract && t.IsSealed))
            {
                IsStatic = true;
                baseType = baseType == typeof(object) ?  null : baseType;
            }
        }
Ejemplo n.º 7
0
    static void GenLuaBinder()
    {
        if (!beAutoGen && EditorApplication.isCompiling)
        {
            EditorUtility.DisplayDialog("警告", "请等待编辑器完成编译再执行此功能", "确定");
            return;
        }

        allTypes.Clear();
        ToLuaTree <string>  tree   = InitTree();
        StringBuilder       sb     = new StringBuilder();
        List <DelegateType> dtList = new List <DelegateType>();

        List <DelegateType> list = new List <DelegateType>();

        list.AddRange(CustomSettings.customDelegateList);
        HashSet <Type> set = GetCustomTypeDelegates();

        List <BindType> backupList = new List <BindType>();

        backupList.AddRange(allTypes);
        ToLuaNode <string> root = tree.GetRoot();

        foreach (Type t in set)
        {
            if (null == list.Find((p) => { return(p.type == t); }))
            {
                DelegateType dt = new DelegateType(t);
                AddSpaceNameToTree(tree, root, dt.type.Namespace);
                list.Add(dt);
            }
        }

        sb.AppendLineEx("//this source code was auto-generated by tolua#, do not modify it");
        sb.AppendLineEx("using System;");
        sb.AppendLineEx("using UnityEngine;");
        sb.AppendLineEx("using LuaInterface;");
        sb.AppendLineEx();
        sb.AppendLineEx("public static class LuaBinder");
        sb.AppendLineEx("{");
        sb.AppendLineEx("\tpublic static void Bind(LuaState L)");
        sb.AppendLineEx("\t{");
        sb.AppendLineEx("\t\tfloat t = Time.realtimeSinceStartup;");
        sb.AppendLineEx("\t\tL.BeginModule(null);");

        for (int i = 0; i < allTypes.Count; i++)
        {
            Type dt = CustomSettings.dynamicList.Find((p) => { return(allTypes[i].type == p); });

            if (dt == null && allTypes[i].nameSpace == null)
            {
                string str = "\t\t" + allTypes[i].wrapName + "Wrap.Register(L);\r\n";
                sb.Append(str);
                allTypes.RemoveAt(i--);
            }
        }

        Action <ToLuaNode <string> > begin = (node) =>
        {
            if (node.value == null)
            {
                return;
            }

            sb.AppendFormat("\t\tL.BeginModule(\"{0}\");\r\n", node.value);
            string space = GetSpaceNameFromTree(node);

            for (int i = 0; i < allTypes.Count; i++)
            {
                Type dt = CustomSettings.dynamicList.Find((p) => { return(allTypes[i].type == p); });

                if (dt == null && allTypes[i].nameSpace == space)
                {
                    string str = "\t\t" + allTypes[i].wrapName + "Wrap.Register(L);\r\n";
                    sb.Append(str);
                    allTypes.RemoveAt(i--);
                }
            }

            string funcName = null;

            for (int i = 0; i < list.Count; i++)
            {
                DelegateType dt        = list[i];
                Type         type      = dt.type;
                string       typeSpace = ToLuaExport.GetNameSpace(type, out funcName);

                if (typeSpace == space)
                {
                    funcName = ToLuaExport.ConvertToLibSign(funcName);
                    string abr = dt.abr;
                    abr = abr == null ? funcName : abr;
                    sb.AppendFormat("\t\tL.RegFunction(\"{0}\", {1});\r\n", abr, dt.name);
                    dtList.Add(dt);
                }
            }
        };

        Action <ToLuaNode <string> > end = (node) =>
        {
            if (node.value != null)
            {
                sb.AppendLineEx("\t\tL.EndModule();");
            }
        };

        tree.DepthFirstTraversal(begin, end, tree.GetRoot());
        sb.AppendLineEx("\t\tL.EndModule();");

        if (CustomSettings.dynamicList.Count > 0)
        {
            sb.AppendLineEx("\t\tL.BeginPreLoad();");

            for (int i = 0; i < CustomSettings.dynamicList.Count; i++)
            {
                Type     t1 = CustomSettings.dynamicList[i];
                BindType bt = backupList.Find((p) => { return(p.type == t1); });
                sb.AppendFormat("\t\tL.AddPreLoad(\"{0}\", LuaOpen_{1}, typeof({0}));\r\n", bt.name, bt.wrapName);
            }

            sb.AppendLineEx("\t\tL.EndPreLoad();");
        }

        sb.AppendLineEx("\t\tDebugger.Log(\"Register lua type cost time: {0}\", Time.realtimeSinceStartup - t);");
        sb.AppendLineEx("\t}");

        for (int i = 0; i < dtList.Count; i++)
        {
            ToLuaExport.GenEventFunction(dtList[i].type, sb);
        }

        if (CustomSettings.dynamicList.Count > 0)
        {
            for (int i = 0; i < CustomSettings.dynamicList.Count; i++)
            {
                Type     t  = CustomSettings.dynamicList[i];
                BindType bt = backupList.Find((p) => { return(p.type == t); });
                GenPreLoadFunction(bt, sb);
            }
        }

        sb.AppendLineEx("}\r\n");
        allTypes.Clear();
        string file = CustomSettings.saveDir + "LuaBinder.cs";

        using (StreamWriter textWriter = new StreamWriter(file, false, Encoding.UTF8))
        {
            textWriter.Write(sb.ToString());
            textWriter.Flush();
            textWriter.Close();
        }

        AssetDatabase.Refresh();
        Debugger.Log("Generate LuaBinder over !");
    }
Ejemplo n.º 8
0
    static void GenLuaBinder()
    {
        if (!beAutoGen && EditorApplication.isCompiling)
        {
            EditorUtility.DisplayDialog("警告", "请等待编辑器完成编译在执行此功能", "确定");
            return;
        }

        allTypes.Clear();
        ToLuaTree <string>  tree   = InitTree();
        StringBuilder       sb     = new StringBuilder();
        List <DelegateType> dtList = new List <DelegateType>();

        sb.AppendLineEx("using System;");
        sb.AppendLineEx("using UnityEngine;");
        sb.AppendLineEx("using LuaInterface;");
        sb.AppendLineEx();
        sb.AppendLineEx("public static class LuaBinder");
        sb.AppendLineEx("{");
        sb.AppendLineEx("\tpublic static void Bind(LuaState L)");
        sb.AppendLineEx("\t{");
        sb.AppendLineEx("\t\tfloat t = Time.realtimeSinceStartup;");
        sb.AppendLineEx("\t\tL.BeginModule(null);");

        //if (File.Exists(CustomSettings.saveDir + "DelegateFactoryWrap.cs"))
        //{
        //    sb.AppendLineEx("\t\tDelegateFactoryWrap.Register(L);");
        //}

        for (int i = 0; i < allTypes.Count; i++)
        {
            if (allTypes[i].nameSpace == null)
            {
                string str = "\t\t" + allTypes[i].wrapName + "Wrap.Register(L);\r\n";
                sb.Append(str);
                allTypes.RemoveAt(i--);
            }
        }

        Action <ToLuaNode <string> > begin = (node) =>
        {
            if (node.value == null)
            {
                return;
            }

            sb.AppendFormat("\t\tL.BeginModule(\"{0}\");\r\n", node.value);
            string space = GetSpaceNameFromTree(node);

            for (int i = 0; i < allTypes.Count; i++)
            {
                if (allTypes[i].nameSpace == space)
                {
                    string str = "\t\t" + allTypes[i].wrapName + "Wrap.Register(L);\r\n";
                    sb.Append(str);
                    allTypes.RemoveAt(i--);
                }
            }

            string funcName = null;

            for (int i = 0; i < CustomSettings.customDelegateList.Length; i++)
            {
                DelegateType dt   = CustomSettings.customDelegateList[i];
                Type         type = CustomSettings.customDelegateList[i].type;

                if (type.Namespace == space)
                {
                    ToLuaExport.GetNameSpace(type, out funcName);
                    funcName = ToLuaExport.ConvertToLibSign(funcName);
                    string abr = dt.abr;
                    abr = abr == null ? funcName : abr;
                    sb.AppendFormat("\t\tL.RegFunction(\"{0}\", {1});\r\n", abr, dt.name);
                    dtList.Add(dt);
                }
            }
        };

        Action <ToLuaNode <string> > end = (node) =>
        {
            if (node.value != null)
            {
                sb.AppendLineEx("\t\tL.EndModule();");
            }
        };

        tree.DepthFirstTraversal(begin, end, tree.GetRoot());

        sb.AppendLineEx("\t\tL.EndModule();");
        sb.AppendLineEx("\t\tDebugger.Log(\"Register lua type cost time: {0}\", Time.realtimeSinceStartup - t);");
        sb.AppendLineEx("\t}");

        for (int i = 0; i < dtList.Count; i++)
        {
            ToLuaExport.GenEventFunction(dtList[i].type, sb);
        }

        sb.AppendLineEx("}\r\n");
        allTypes.Clear();
        string file = CustomSettings.saveDir + "LuaBinder.cs";

        using (StreamWriter textWriter = new StreamWriter(file, false, Encoding.UTF8))
        {
            textWriter.Write(sb.ToString());
            textWriter.Flush();
            textWriter.Close();
        }

        AssetDatabase.Refresh();
    }
Ejemplo n.º 9
0
            public BindType(Type t)
            {
                type      = t;
                nameSpace = ToLuaExport.GetNameSpace(t, out libName);
                className = ToLuaExport.CombineTypeStr(nameSpace, libName);
                libName   = ToLuaExport.ConvertToLibSign(libName);

                if (typeof(System.Delegate).IsAssignableFrom(t) || typeof(System.MulticastDelegate).IsAssignableFrom(t))
                {
                    isDelegate   = true;
                    typeClassify = "delegate";
                }
                else
                {
                    if (className == "object")
                    {
                        wrapName  = "System_Object";
                        className = "System.Object";
                    }
                    else if (className == "string")
                    {
                        wrapName  = "System_String";
                        className = "System.String";
                    }
                    else
                    {
                        wrapName = className.Replace('.', '_');
                        wrapName = ToLuaExport.ConvertToLibSign(wrapName);
                    }
                    wrapName += "Wrap";
                    if (t.BaseType != null && t.BaseType != typeof(ValueType))
                    {
                        baseClass = t.BaseType.AssemblyQualifiedName;
                    }

                    if ((t.GetConstructor(Type.EmptyTypes) == null && t.IsAbstract && t.IsSealed))
                    {
                        isStatic  = true;
                        baseClass = baseClass == typeof(object).AssemblyQualifiedName ? null : baseClass;
                    }
                    if (t.IsAbstract)
                    {
                        typeClassify = "abstract";
                    }
                    else if (t.IsInterface)
                    {
                        typeClassify = "interface";
                    }
                    else if (t.IsEnum)
                    {
                        typeClassify = "enum";
                    }
                    else if (t.IsClass && isStatic)
                    {
                        typeClassify = "static class";
                    }
                    else
                    {
                        typeClassify = "class";
                    }
                }
            }
Ejemplo n.º 10
0
        public void GenLuaBinder()
        {
            StringBuilder       sb     = new StringBuilder();
            List <DelegateType> dtList = new List <DelegateType>();

            List <BindType>     allTypes     = GetAllWrappedCustomType();
            List <DelegateType> delegateList = GetAllBuildedDelegate();
            ToLuaTree <string>  tree         = InitTree(allTypes, delegateList);

            List <BindType> preloadList = GetAllPreloadType();

            List <BindType> backupList = new List <BindType>();

            backupList.AddRange(allTypes);

            sb.AppendLine("//this source code was auto-generated by tolua#, do not modify it");
            sb.AppendLine("using System;");
            sb.AppendLine("using UnityEngine;");
            sb.AppendLine("using LaoHan.Infrastruture.ulua;");
            sb.AppendLine();
            sb.AppendLine("public static class LuaBinder");
            sb.AppendLine("{");
            sb.AppendLine("\tpublic static void Bind(LuaState L)");
            sb.AppendLine("\t{");
            sb.AppendLine("\t\tfloat t = Time.realtimeSinceStartup;");
            sb.AppendLine("\t\tL.BeginModule(null);");

            for (int i = 0; i < allTypes.Count; i++)
            {
                BindType dt = preloadList.Find((p) => { return(allTypes[i].type == p.type); });

                if (dt == null && allTypes[i].nameSpace == null)
                {
                    string str = "\t\t" + allTypes[i].wrapName + ".Register(L);\r\n";
                    sb.Append(str);
                    allTypes.RemoveAt(i--);
                }
            }

            Action <ToLuaNode <string> > begin = (node) =>
            {
                if (node.value == null)
                {
                    return;
                }

                sb.AppendFormat("\t\tL.BeginModule(\"{0}\");\r\n", node.value);
                string space = GetSpaceNameFromTree(node);

                for (int i = 0; i < allTypes.Count; i++)
                {
                    BindType dt = preloadList.Find((p) => { return(allTypes[i].type == p.type); });

                    if (dt == null && allTypes[i].nameSpace == space)
                    {
                        string str = "\t\t" + allTypes[i].wrapName + ".Register(L);\r\n";
                        sb.Append(str);
                        allTypes.RemoveAt(i--);
                    }
                }

                string funcName = null;

                for (int i = 0; i < delegateList.Count; i++)
                {
                    DelegateType dt        = delegateList[i];
                    Type         type      = dt.type;
                    string       typeSpace = ToLuaExport.GetNameSpace(type, out funcName);

                    if (typeSpace == space)
                    {
                        funcName = ToLuaExport.ConvertToLibSign(funcName);
                        string abr = dt.abr;
                        abr = abr == null ? funcName : abr;
                        sb.AppendFormat("\t\tL.RegFunction(\"{0}\", {1});\r\n", abr, dt.name);
                        dtList.Add(dt);
                    }
                }
            };

            Action <ToLuaNode <string> > end = (node) =>
            {
                if (node.value != null)
                {
                    sb.AppendLine("\t\tL.EndModule();");
                }
            };

            tree.DepthFirstTraversal(begin, end, tree.GetRoot());
            sb.AppendLine("\t\tL.EndModule();");

            if (preloadList.Count > 0)
            {
                sb.AppendLine("\t\tL.BeginPreLoad();");

                for (int i = 0; i < preloadList.Count; i++)
                {
                    BindType t1 = preloadList[i];
                    BindType bt = backupList.Find((p) => { return(p.type == t1.type); });
                    sb.AppendFormat("\t\tL.AddPreLoad(\"{0}\", LuaOpen_{1}, typeof({0}));\r\n", bt.className, bt.wrapName);
                }
                sb.AppendLine("\t\tL.EndPreLoad();");
            }

            //sb.AppendLine("\t\tDebugger.Log(\"Register lua type cost time: {0}\", Time.realtimeSinceStartup - t);");
            sb.AppendLine("\t}");

            for (int i = 0; i < dtList.Count; i++)
            {
                ToLuaExport.GenEventFunction(dtList[i].type, sb);
            }

            if (preloadList.Count > 0)
            {
                for (int i = 0; i < preloadList.Count; i++)
                {
                    BindType t  = preloadList[i];
                    BindType bt = backupList.Find((p) => { return(p.type == t.type); });
                    GenPreLoadFunction(bt, sb);
                }
            }

            sb.AppendLine("}\r\n");
            allTypes.Clear();
            using (StreamWriter textWriter = new StreamWriter(luaBinderFilePath, false, Encoding.UTF8))
            {
                textWriter.Write(sb.ToString());
                textWriter.Flush();
                textWriter.Close();
            }

            lhDebug.Log("Generate LuaBinder over !");
        }
Ejemplo n.º 11
0
 public DelegateType(Type t)
 {
     type    = t;
     strType = ToLuaExport.GetTypeStr(t);
     name    = ToLuaExport.ConvertToLibSign(strType);
 }