private void RegisterCheckParamCount(int indent, StringBuilder sb)
        {
            int minParamCount = parTypes.Count;

            if (parDefaultStartIndex != -1)
            {
                minParamCount = parDefaultStartIndex;
            }
            else
            {
                if (isParams)
                {
                    minParamCount -= 1;
                }
            }

            if (!methodInfo.IsStatic)
            {
                minParamCount += 1;
            }

            string indentStr = CSToLuaRegisterHelper.GetIndent(indent);

            sb.AppendLine(string.Format("{0}int top = luaState.GetTop();", indentStr));
            sb.AppendLine(string.Format("{0}if(top< {1}){{", indentStr, minParamCount));
            indent++;
            indentStr = CSToLuaRegisterHelper.GetIndent(indent);
            sb.AppendLine(string.Format("{0}UnityEngine.Debug.LogError(\"Count not enough!!\");", indentStr));
            sb.AppendLine(string.Format("{0}return 0;", indentStr));
            indent--;
            indentStr = CSToLuaRegisterHelper.GetIndent(indent);
            sb.AppendLine(string.Format("{0}}}", indentStr));
        }
        private void RegisterReturnMethod(int indent, StringBuilder sb)
        {
            int returnCount = 0;

            if (methodInfo.ReturnType == typeof(void))
            {
                returnCount = 0;
            }
            else
            {
                sb.Append(CSToLuaRegisterHelper.GetPushAction(indent, methodInfo.ReturnType, "rv"));
                returnCount += 1;
            }
            returnCount += parRefIndex.Count;
            returnCount += parOutIndex.Count;

            for (int i = 0; i < parRefIndex.Count; i++)
            {
                sb.Append(CSToLuaRegisterHelper.GetPushAction(indent, parTypes[parRefIndex[i]], "v" + parRefIndex[i]));
            }
            for (int i = 0; i < parOutIndex.Count; i++)
            {
                sb.Append(CSToLuaRegisterHelper.GetPushAction(indent, parTypes[parOutIndex[i]], "v" + parOutIndex[i]));
            }

            sb.AppendLine(string.Format("{0}return {1};", CSToLuaRegisterHelper.GetIndent(indent), returnCount));
        }
        //no param
        private void RegisterNMethod(int indent, StringBuilder sb)
        {
            string indentStr = CSToLuaRegisterHelper.GetIndent(indent);

            if (methodInfo.ReturnType == typeof(void))
            {
                if (methodInfo.IsStatic)
                {
                    sb.AppendLine(string.Format("{0}{1}.{2}();", indentStr, classRegister.RegisterType, methodInfo.Name));
                }
                else
                {
                    sb.AppendLine(string.Format("{0}obj.{1}();", indentStr, methodInfo.Name));
                }
            }
            else
            {
                if (methodInfo.IsStatic)
                {
                    sb.AppendLine(string.Format("{0}{1} rv = {2}.{3}();", indentStr, CSToLuaRegisterHelper.GetTypeFullName(methodInfo.ReturnType), classRegister.RegisterType, methodInfo.Name));
                }
                else
                {
                    sb.AppendLine(string.Format("{0}{1} rv = obj.{2}();", indentStr, CSToLuaRegisterHelper.GetTypeFullName(methodInfo.ReturnType), methodInfo.Name));
                }
            }
        }
 public string RegisterActionToLua(int indent)
 {
     if (constructorInfo == null || constructorInfo.Length == 0)
     {
         return("");
     }
     return(CSToLuaRegisterHelper.GetRegisterAction(indent, "CreateInstance", "__call"));
 }
        private void RegisterParamsDefaultMethod(int indent, StringBuilder sb, int startIndex)
        {
            string indentStr = CSToLuaRegisterHelper.GetIndent(indent);

            sb.AppendLine(string.Format("{0}if(top > " + (startIndex + parDefaultStartIndex - 2) + " && top < " + (startIndex + parTypes.Count - 1) + "){{", indentStr));
            RegisterNParamsDefaultMethod(indent + 1, sb, startIndex, true);
            RegisterReturnMethod(indent + 1, sb);
            sb.AppendLine(string.Format("{0}}}else{{", indentStr));
            RegisterParamsNDefaultMethod(indent + 1, sb, startIndex);
            RegisterReturnMethod(indent + 1, sb);
            sb.AppendLine(string.Format("{0}}}", indentStr));
        }
Esempio n. 6
0
        private void RegisterConstructor()
        {
            if (!CSToLuaRegisterManager.GetInstance().IsConstructorExport(CSToLuaRegisterHelper.GetTypeFullName(registerType)))
            {
                return;
            }

            ConstructorInfo[] cInfos = registerType.GetConstructors(BindingFlags.Public | BindingFlags.Instance);
            if (cInfos != null && cInfos.Length > 0)
            {
                registerList.Add(new CSToLuaConstructorRegister(this, cInfos));
            }
        }
        public string RegisterActionToLua(int indent)
        {
            StringBuilder sb = new StringBuilder();

            if (propertyType == CSToLuaPropertyType.Get || propertyType == CSToLuaPropertyType.GetSet)
            {
                sb.Append(CSToLuaRegisterHelper.GetRegisterAction(indent, GetFunName(CSToLuaPropertyType.Get), "get_" + propertyInfo.Name));
            }
            if (propertyType == CSToLuaPropertyType.Set || propertyType == CSToLuaPropertyType.GetSet)
            {
                sb.Append(CSToLuaRegisterHelper.GetRegisterAction(indent, GetFunName(CSToLuaPropertyType.Set), "set_" + propertyInfo.Name));
            }
            return(sb.ToString());
        }
        public string RegisterFunctionToLua(int indent)
        {
            CSToLuaRegisterManager.GetInstance().DebugLog("    " + methodInfo.Name);

            ParameterInfo[] pInfos = methodInfo.GetParameters();
            StringBuilder   sb     = new StringBuilder();

            sb.Append(CSToLuaRegisterHelper.GetRegisterFunStart(indent, "Method_" + altasName));
            if (!methodInfo.IsStatic)
            {
                indent++;
                sb.Append(CSToLuaRegisterHelper.GetToUserDataAction(indent, classRegister.RegisterType, 1, "obj"));
                indent--;
            }
            indent++;
            if (pInfos == null || pInfos.Length == 0)
            {
                RegisterNMethod(indent, sb);
                RegisterReturnMethod(indent, sb);
            }
            else
            {
                RegisterCheckParamCount(indent, sb);
                if (!isParams && parDefaultStartIndex == -1)
                {
                    RegisterNPamasNDefaultMethod(indent, sb, methodInfo.IsStatic ? 1 : 2);
                    RegisterReturnMethod(indent, sb);
                }
                else if (!isParams && parDefaultStartIndex >= 0)
                {
                    RegisterNParamsDefaultMethod(indent, sb, methodInfo.IsStatic ? 1 : 2);
                    RegisterReturnMethod(indent, sb);
                }
                else if (isParams && parDefaultStartIndex == -1)
                {
                    RegisterParamsNDefaultMethod(indent, sb, methodInfo.IsStatic ? 1 : 2);
                    RegisterReturnMethod(indent, sb);
                }
                else
                {
                    RegisterParamsDefaultMethod(indent, sb, methodInfo.IsStatic ? 1 : 2);
                }
            }
            indent--;
            sb.Append(CSToLuaRegisterHelper.GetRegisterFunEnd(indent));
            return(sb.ToString());
        }
        // no params ,no default value
        private void RegisterNPamasNDefaultMethod(int indent, StringBuilder sb, int startIndex)
        {
            string        indentStr = CSToLuaRegisterHelper.GetIndent(indent);
            List <string> values    = new List <string>();

            for (int i = 0; i < parTypes.Count; i++)
            {
                sb.Append(CSToLuaRegisterHelper.GetToAction(indent, parTypes[i], startIndex + i, "v" + i));
                if (parRefIndex.IndexOf(i) >= 0)
                {
                    values.Add("ref v" + i);
                }
                else if (parOutIndex.IndexOf(i) >= 0)
                {
                    values.Add("out v" + i);
                }
                else
                {
                    values.Add("v" + i);
                }
            }
            if (methodInfo.ReturnType == typeof(void))
            {
                if (methodInfo.IsStatic)
                {
                    sb.AppendLine(string.Format("{0}{1}.{2}({3});", indentStr, classRegister.RegisterType, methodInfo.Name, string.Join(",", values.ToArray())));
                }
                else
                {
                    sb.AppendLine(string.Format("{0}obj.{1}({2});", indentStr, methodInfo.Name, string.Join(",", values.ToArray())));
                }
            }
            else
            {
                if (methodInfo.IsStatic)
                {
                    sb.AppendLine(string.Format("{0}{1} rv = {2}.{3}({4});", indentStr, CSToLuaRegisterHelper.GetTypeFullName(methodInfo.ReturnType), classRegister.RegisterType, methodInfo.Name, string.Join(",", values.ToArray())));
                }
                else
                {
                    sb.AppendLine(string.Format("{0}{1} rv = obj.{2}({3});", indentStr, CSToLuaRegisterHelper.GetTypeFullName(methodInfo.ReturnType), methodInfo.Name, string.Join(",", values.ToArray())));
                }
            }
        }
        public string RegisterFunctionToLua(int indent)
        {
            if (constructorInfo == null || constructorInfo.Length == 0)
            {
                return("");
            }

            StringBuilder sb        = new StringBuilder();
            string        indentStr = "";

            sb.Append(CSToLuaRegisterHelper.GetRegisterFunStart(indent, "CreateInstance"));

            indent++;
            indentStr = CSToLuaRegisterHelper.GetIndent(indent);
            sb.AppendLine(string.Format("{0}int top = luaState.GetTop();", indentStr));
            sb.AppendLine(string.Format("{0}System.Object[] pInfos = new System.Object[top-1];", indentStr));
            sb.AppendLine(string.Format("{0}for(int i =0;i<top -1;i++){{", indentStr));
            indent++;
            indentStr = CSToLuaRegisterHelper.GetIndent(indent);
            sb.AppendLine(string.Format("{0}pInfos[i] = luaState.ToSystemObject(i+2,typeof(System.Object));", indentStr));
            indent--;
            indentStr = CSToLuaRegisterHelper.GetIndent(indent);
            sb.AppendLine(string.Format("{0}}}", indentStr));
            sb.AppendLine(string.Format("{0}try{{", indentStr));
            indent++;
            indentStr = CSToLuaRegisterHelper.GetIndent(indent);
            sb.AppendLine(string.Format("{0}{1} obj = ({1})System.Activator.CreateInstance(typeof({1}), pInfos);", indentStr, CSToLuaRegisterHelper.GetTypeFullName(classRegister.RegisterType)));
            sb.Append(CSToLuaRegisterHelper.GetPushAction(indent, classRegister.RegisterType, "obj"));
            indent--;
            indentStr = CSToLuaRegisterHelper.GetIndent(indent);
            sb.AppendLine(string.Format("{0}}}catch{{", indentStr));
            indent++;
            indentStr = CSToLuaRegisterHelper.GetIndent(indent);
            sb.AppendLine(string.Format("{0}luaState.PushNil();", indentStr));
            indent--;
            indentStr = CSToLuaRegisterHelper.GetIndent(indent);
            sb.AppendLine(string.Format("{0}}}", indentStr));
            sb.AppendLine(string.Format("{0}return 1;", indentStr));
            indent--;

            sb.Append(CSToLuaRegisterHelper.GetRegisterFunEnd(indent));

            return(sb.ToString());
        }
Esempio n. 11
0
        public string RegisterToLua()
        {
            int           indent    = 0;
            string        indentStr = "";
            StringBuilder sb        = new StringBuilder();

            sb.AppendLine("public static class " + GetRegisterFileName() + "{");
            indent++;
            indentStr = CSToLuaRegisterHelper.GetIndent(indent);
            sb.AppendLine(string.Format("{0}private static Game.Core.DotLua.LuaState luaState;", indentStr));
            sb.AppendLine(string.Format("{0}public static int RegisterToLua(Game.Core.DotLua.LuaState lua){{", indentStr));
            indent++;
            indentStr = CSToLuaRegisterHelper.GetIndent(indent);
            sb.AppendLine(string.Format("{0}luaState = lua;", indentStr));
            sb.AppendLine(string.Format("{0}luaState.NewTable();", indentStr));
            sb.AppendLine(string.Format("{0}luaState.PushValue(-1);", indentStr));
            sb.AppendLine(string.Format("{0}luaState.SetField(-2,\"__index\");", indentStr));
            sb.AppendLine(string.Format("{0}luaState.PushValue(-1);", indentStr));
            sb.AppendLine(string.Format("{0}luaState.SetGlobal(\"{1}\");", indentStr, registerType.Name));
            sb.AppendLine(string.Format("{0}luaState.PushValue(-1);", indentStr));
            sb.AppendLine(string.Format("{0}luaState.SetMetaTable(-2);", indentStr));

            foreach (ICSToLuaRegister register in registerList)
            {
                sb.Append(register.RegisterActionToLua(indent));
            }

            sb.AppendLine(string.Format("{0}return luaState.L_Ref(Game.Core.DotLua.LuaAPI.LUA_REGISTRYINDEX);", indentStr));

            indent--;
            sb.AppendLine(string.Format("{0}}}", CSToLuaRegisterHelper.GetIndent(indent)));

            foreach (ICSToLuaRegister register in registerList)
            {
                sb.Append(register.RegisterFunctionToLua(indent));
            }

            sb.AppendLine("}");

            return(sb.ToString());
        }
Esempio n. 12
0
        private string RegisterGetFunction(int indent)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(CSToLuaRegisterHelper.GetRegisterFunStart(indent, GetFunName(CSToLuaFieldType.Get)));
            indent++;
            if (fieldInfo.IsStatic)
            {
                sb.Append(CSToLuaRegisterHelper.GetPushAction(indent, fieldInfo.FieldType, CSToLuaRegisterHelper.GetTypeFullName(classRegister.RegisterType) + "." + fieldInfo.Name));
            }
            else
            {
                sb.Append(CSToLuaRegisterHelper.GetToUserDataAction(indent, classRegister.RegisterType, 1, "obj"));
                sb.Append(CSToLuaRegisterHelper.GetPushAction(indent, fieldInfo.FieldType, "obj." + fieldInfo.Name));
            }
            sb.AppendLine(string.Format("{0}return 1;", CSToLuaRegisterHelper.GetIndent(indent)));
            indent--;
            sb.Append(CSToLuaRegisterHelper.GetRegisterFunEnd(indent));

            return(sb.ToString());
        }
Esempio n. 13
0
        private string RegisterGetSetFunction(int indent)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(CSToLuaRegisterHelper.GetRegisterFunStart(indent, GetFunName(CSToLuaFieldType.GetSet)));
            indent++;
            sb.AppendLine(string.Format("{0}int top = luaState.GetTop();", CSToLuaRegisterHelper.GetIndent(indent)));
            sb.AppendLine(string.Format("{0}if(top == 0){{", CSToLuaRegisterHelper.GetIndent(indent)));
            indent++;
            sb.AppendLine(string.Format("{0}return {1}(ptr);", CSToLuaRegisterHelper.GetIndent(indent), GetFunName(CSToLuaFieldType.Get)));
            indent--;
            sb.AppendLine(string.Format("{0}}}else{{", CSToLuaRegisterHelper.GetIndent(indent)));
            indent++;
            sb.AppendLine(string.Format("{0}return {1}(ptr);", CSToLuaRegisterHelper.GetIndent(indent), GetFunName(CSToLuaFieldType.Set)));
            indent--;
            sb.AppendLine(string.Format("{0}}}", CSToLuaRegisterHelper.GetIndent(indent)));
            indent--;
            sb.Append(CSToLuaRegisterHelper.GetRegisterFunEnd(indent));

            return(sb.ToString());
        }
Esempio n. 14
0
        public void ConvertCSToLua(string dir)
        {
            if (aConfig == null || aConfig.exportClasses == null || aConfig.exportClasses.Count == 0)
            {
                return;
            }

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            StringBuilder sb = new StringBuilder();

            sb.AppendLine("using Game.Core.DotLua;");
            sb.AppendLine("public static class CSToLua{");
            sb.AppendLine("public static void InitStaticRegistToLua(){");

            foreach (ClassConfig cc in aConfig.exportClasses)
            {
                Type type = CSToLuaRegisterHelper.GetTypeByName(cc.name);
                if (type != null)
                {
                    DebugLog(cc.name);

                    CSToLuaClassRegister cr = new CSToLuaClassRegister(type);
                    string script           = cr.RegisterToLua();
                    string filePath         = dir + "/" + cr.GetRegisterFileName() + ".cs";
                    File.WriteAllText(filePath, script);

                    sb.AppendLine(string.Format("LuaInstance.instance.RegisterData.AddStaticRegisterData(new LuaStaticRegisterData(typeof({0}),{1}.RegisterToLua));", CSToLuaRegisterHelper.GetTypeFullName(cr.RegisterType), cr.GetRegisterFileName()));
                }
            }

            sb.AppendLine("}}");

            string cstoluaPath = dir + "/CSToLua.cs";

            File.WriteAllText(cstoluaPath, sb.ToString());
        }
        private string RegisterSetFunction(int indent)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(CSToLuaRegisterHelper.GetRegisterFunStart(indent, GetFunName(CSToLuaPropertyType.Set)));
            indent++;
            if (propertyInfo.GetSetMethod().IsStatic)
            {
                sb.Append(CSToLuaRegisterHelper.GetToAction(indent, propertyInfo.PropertyType, 1, "v"));
                sb.AppendLine(string.Format("{0}{1}.{2} = v;", CSToLuaRegisterHelper.GetIndent(indent), CSToLuaRegisterHelper.GetTypeFullName(classRegister.RegisterType), propertyInfo.Name));
            }
            else
            {
                sb.Append(CSToLuaRegisterHelper.GetToUserDataAction(indent, classRegister.RegisterType, 1, "obj"));
                sb.Append(CSToLuaRegisterHelper.GetToAction(indent, propertyInfo.PropertyType, 2, "v"));
                sb.AppendLine(string.Format("{0}obj.{1} = v;", CSToLuaRegisterHelper.GetIndent(indent), propertyInfo.Name));
            }
            sb.AppendLine(string.Format("{0}return 0;", CSToLuaRegisterHelper.GetIndent(indent)));
            indent--;
            sb.Append(CSToLuaRegisterHelper.GetRegisterFunEnd(indent));

            return(sb.ToString());
        }
Esempio n. 16
0
 public string GetRegisterFileName()
 {
     return("CTL_" + CSToLuaRegisterHelper.GetTypeFullName(registerType).Replace(".", "_"));
 }
Esempio n. 17
0
        //[MenuItem("MHJ/Lua/Create Config")]
        public static void ExportXMLByRegisterTxt()
        {
            AssemblyConfig config     = null;
            string         configPath = Application.dataPath.Replace("\\", "/") + "/ClientCode/client-tools/CSRegisterToLua/config.xml";

            if (File.Exists(configPath))
            {
                config = AssemblyConfig.Deserialize(File.ReadAllText(configPath));
            }
            else
            {
                config = new AssemblyConfig();
            }

            string        filePath = Application.streamingAssetsPath.Replace("\\", "/") + "/Script/Utils/RegisterClass.txt";
            String        content  = File.ReadAllText(filePath);
            StringReader  sr       = new StringReader(content);
            List <string> delList  = new List <string>();
            string        line     = null;

            while ((line = sr.ReadLine()) != null)
            {
                line = line.Trim();
                if (line.StartsWith("--"))
                {
                    continue;
                }
                if (line.StartsWith("Register.RegisterClass"))
                {
                    line = line.Replace("Register.RegisterClass", "");
                    line = line.Substring(line.IndexOf("\"") + 1, line.LastIndexOf("\"") - 2);
                    ClassConfig classConfig = null;
                    //if(line.StartsWith("PBProto") || line.StartsWith("t3config"))
                    {
                        bool isNew = true;
                        foreach (ClassConfig cc in config.exportClasses)
                        {
                            if (cc.name == line)
                            {
                                classConfig = cc;
                                isNew       = false;
                                break;
                            }
                        }
                        if (isNew)
                        {
                            classConfig      = new ClassConfig();
                            classConfig.name = line;
                            config.exportClasses.Add(classConfig);
                        }

                        if (classConfig != null)
                        {
                            if (classConfig.name.StartsWith("PBProto"))
                            {
                                classConfig.isConstructor = true;
                            }
                        }
                    }
                }
            }

            FileInfo      fi = new FileInfo(configPath);
            DirectoryInfo di = fi.Directory;

            if (!di.Exists)
            {
                di.Create();
            }

            for (int i = config.exportClasses.Count - 1; i >= 0; i--)
            {
                Type type  = CSToLuaRegisterHelper.GetTypeByName(config.exportClasses[i].name);
                bool isDel = false;
                if (type == null)
                {
                    isDel = true;
                }
                if (!isDel)
                {
                    EventInfo[] events = type.GetEvents(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);
                    if (events != null && events.Length > 0)
                    {
                        isDel = true;
                    }
                }
                if (!isDel)
                {
                    FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);
                    foreach (FieldInfo f in fields)
                    {
                        if (f.FieldType.IsSubclassOf(typeof(Delegate)))
                        {
                            isDel = true;
                            break;
                        }
                    }
                }

                if (!isDel)
                {
                    PropertyInfo[] properties = type.GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static | BindingFlags.FlattenHierarchy);
                    foreach (PropertyInfo p in properties)
                    {
                        if (p.PropertyType.IsSubclassOf(typeof(Delegate)))
                        {
                            isDel = true;
                            break;
                        }
                    }
                }
                if (!isDel)
                {
                    if (type.IsGenericType)
                    {
                        isDel = true;
                    }
                }

                if (isDel)
                {
                    config.exportClasses.RemoveAt(i);
                }
            }

            AssemblyConfig.Serialize(configPath, config);
            AssetDatabase.Refresh();
        }
Esempio n. 18
0
 public string RegisterActionToLua(int indent)
 {
     return(CSToLuaRegisterHelper.GetRegisterAction(indent, GetFunName(fieldType), fieldInfo.Name));
 }
 public string RegisterActionToLua(int indent)
 {
     return(CSToLuaRegisterHelper.GetRegisterAction(indent, "Method_" + altasName, altasName));
 }
        //No params but have default
        private void RegisterNParamsDefaultMethod(int indent, StringBuilder sb, int startIndex, bool ingoreLast = false)
        {
            string        indentStr = CSToLuaRegisterHelper.GetIndent(indent);
            List <string> values    = new List <string>();

            for (int i = 0; i < parDefaultStartIndex; i++)
            {
                sb.Append(CSToLuaRegisterHelper.GetToAction(indent, parTypes[i], startIndex + i, "v" + i));
                if (parRefIndex.IndexOf(i) >= 0)
                {
                    values.Add("ref v" + i);
                }
                else if (parOutIndex.IndexOf(i) >= 0)
                {
                    values.Add("out v" + i);
                }
                else
                {
                    values.Add("v" + i);
                }
            }

            for (int i = parDefaultStartIndex; i < parTypes.Count; i++)
            {
                string typeName = CSToLuaRegisterHelper.GetTypeFullName(parTypes[i]);
                object defValue = methodInfo.GetParameters()[i].DefaultValue;
                string defStr   = CSToLuaRegisterHelper.GetDefaultValue(defValue, parTypes[i]);
                sb.AppendLine(string.Format("{0}{1} v" + i + " = {2};", indentStr, typeName, defStr));
            }
            if (methodInfo.ReturnType != typeof(void))
            {
                sb.AppendLine(string.Format("{0}{1} rv = {2};", indentStr, CSToLuaRegisterHelper.GetTypeFullName(methodInfo.ReturnType), CSToLuaRegisterHelper.GetDefaultValue(methodInfo.ReturnType)));
            }

            for (int i = 0; i < (ingoreLast ? parTypes.Count - parDefaultStartIndex : parTypes.Count - parDefaultStartIndex + 1); i++)
            {
                sb.AppendLine(string.Format("{0}if(top == {1}){{", indentStr, startIndex + parDefaultStartIndex + i - 1));
                indent++;
                indentStr = CSToLuaRegisterHelper.GetIndent(indent);
                List <string> newValues = new List <string>();
                newValues.AddRange(values);

                for (int j = 0; j < i; j++)
                {
                    sb.Append(CSToLuaRegisterHelper.GetToActionWithNoType(indent, parTypes[parDefaultStartIndex + j], startIndex + parDefaultStartIndex + j, "v" + (parDefaultStartIndex + j)));
                    newValues.Add("v" + (parDefaultStartIndex + j));
                }

                if (methodInfo.ReturnType == typeof(void))
                {
                    if (methodInfo.IsStatic)
                    {
                        sb.AppendLine(string.Format("{0}{1}.{2}({3});", indentStr, classRegister.RegisterType, methodInfo.Name, string.Join(",", newValues.ToArray())));
                    }
                    else
                    {
                        sb.AppendLine(string.Format("{0}obj.{1}({2});", indentStr, methodInfo.Name, string.Join(",", newValues.ToArray())));
                    }
                }
                else
                {
                    if (methodInfo.IsStatic)
                    {
                        sb.AppendLine(string.Format("{0}rv = {1}.{2}({3});", indentStr, classRegister.RegisterType, methodInfo.Name, string.Join(",", newValues.ToArray())));
                    }
                    else
                    {
                        sb.AppendLine(string.Format("{0}rv = obj.{1}({2});", indentStr, methodInfo.Name, string.Join(",", newValues.ToArray())));
                    }
                }
                indent--;
                indentStr = CSToLuaRegisterHelper.GetIndent(indent);
                sb.AppendLine(string.Format("{0}}}", indentStr));
            }
        }
        //have params but no default
        private void RegisterParamsNDefaultMethod(int indent, StringBuilder sb, int startIndex)
        {
            string        indentStr = CSToLuaRegisterHelper.GetIndent(indent);
            List <string> values    = new List <string>();

            for (int i = 0; i < parTypes.Count - 1; i++)
            {
                sb.Append(CSToLuaRegisterHelper.GetToAction(indent, parTypes[i], startIndex + i, "v" + i));
                if (parRefIndex.IndexOf(i) >= 0)
                {
                    values.Add("ref v" + i);
                }
                else if (parOutIndex.IndexOf(i) >= 0)
                {
                    values.Add("out v" + i);
                }
                else
                {
                    values.Add("v" + i);
                }
            }
            Type   paramsType     = parTypes[parTypes.Count - 1];
            string paramsTypeName = CSToLuaRegisterHelper.GetTypeFullName(paramsType);

            paramsTypeName = paramsTypeName.Replace("[]", "");
            Type sPType = CSToLuaRegisterHelper.GetTypeByName(paramsTypeName);

            sb.AppendLine(string.Format("{0}{1}[] ps;", indentStr, paramsTypeName));
            sb.AppendLine(string.Format("{0}if(top > " + (startIndex + parTypes.Count - 2) + "){{", indentStr));
            indent++;
            indentStr = CSToLuaRegisterHelper.GetIndent(indent);
            sb.AppendLine(string.Format("{0}ps = new {1}[{2}];", indentStr, paramsTypeName, (startIndex + parTypes.Count - 3)));
            sb.AppendLine(string.Format("{0}for(int i =0;i<top - " + (startIndex + parTypes.Count - 2) + ";i++){{", indentStr));
            indent++;
            indentStr = CSToLuaRegisterHelper.GetIndent(indent);
            if (CSToLuaRegisterHelper.IsBaseType(sPType))
            {
                sb.AppendLine(string.Format("{0}ps[{1}]={2}luaState.{3}({4});", indentStr, "i", CSToLuaRegisterHelper.GetToTypeCast(sPType),
                                            CSToLuaRegisterHelper.GetToActionStr(sPType), (startIndex + parTypes.Count - 1) + "+i"));
            }
            else
            {
                sb.AppendLine(string.Format("{0}ps[{1}]=({2})luaState.ToSystemObject({3},typeof({2}));", indentStr, "i", paramsTypeName, (startIndex + parTypes.Count - 1) + "+i"));
            }
            indent--;
            indentStr = CSToLuaRegisterHelper.GetIndent(indent);
            sb.AppendLine(string.Format("{0}}}", indentStr));
            indent--;
            indentStr = CSToLuaRegisterHelper.GetIndent(indent);
            sb.AppendLine(string.Format("{0}}}else{{", indentStr));
            indent++;
            indentStr = CSToLuaRegisterHelper.GetIndent(indent);
            sb.AppendLine(string.Format("{0}ps = new {1}[0];", indentStr, paramsTypeName));
            indent--;
            indentStr = CSToLuaRegisterHelper.GetIndent(indent);
            sb.AppendLine(string.Format("{0}}}", indentStr));
            values.Add("ps");
            if (methodInfo.ReturnType == typeof(void))
            {
                if (methodInfo.IsStatic)
                {
                    sb.AppendLine(string.Format("{0}{1}.{2}({3});", indentStr, classRegister.RegisterType, methodInfo.Name, string.Join(",", values.ToArray())));
                }
                else
                {
                    sb.AppendLine(string.Format("{0}obj.{1}({2});", indentStr, methodInfo.Name, string.Join(",", values.ToArray())));
                }
            }
            else
            {
                if (methodInfo.IsStatic)
                {
                    sb.AppendLine(string.Format("{0}{1} rv = {2}.{3}({4});", indentStr, CSToLuaRegisterHelper.GetTypeFullName(methodInfo.ReturnType), classRegister.RegisterType, methodInfo.Name, string.Join(",", values.ToArray())));
                }
                else
                {
                    sb.AppendLine(string.Format("{0}{1} rv = obj.{2}({3});", indentStr, CSToLuaRegisterHelper.GetTypeFullName(methodInfo.ReturnType), methodInfo.Name, string.Join(",", values.ToArray())));
                }
            }
        }