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()); }
public CSToLuaFieldRegister(CSToLuaClassRegister cr, FieldInfo fi) { classRegister = cr; fieldInfo = fi; if (fieldInfo.IsStatic) { if ((fieldInfo.Attributes & FieldAttributes.Literal) == 0) { fieldType = CSToLuaFieldType.GetSet; } fieldType = CSToLuaFieldType.Get; } else { if ((fieldInfo.Attributes & FieldAttributes.Literal) == 0) { fieldType = CSToLuaFieldType.GetSet; } fieldType = CSToLuaFieldType.Get; } }
public CSToLuaPropertyRegister(CSToLuaClassRegister cr, PropertyInfo pi) { classRegister = cr; propertyInfo = pi; MethodInfo getMethod = propertyInfo.GetGetMethod(); MethodInfo setMethod = propertyInfo.GetSetMethod(); if (propertyInfo.CanRead && propertyInfo.CanWrite) { if (setMethod != null && getMethod != null && setMethod.IsPublic && getMethod.IsPublic) { propertyType = CSToLuaPropertyType.GetSet; } else if (setMethod != null && setMethod.IsPublic) { propertyType = CSToLuaPropertyType.Set; } else if (getMethod != null && getMethod.IsPublic) { propertyType = CSToLuaPropertyType.Get; } } else if (propertyInfo.CanRead) { if (getMethod != null && getMethod.IsPublic) { propertyType = CSToLuaPropertyType.Get; } } else { if (setMethod != null && setMethod.IsPublic) { propertyType = CSToLuaPropertyType.Set; } } }
public CSToLuaMethodRegister(CSToLuaClassRegister cr, MethodInfo mi, string name) { methodInfo = mi; classRegister = cr; altasName = name; ParameterInfo[] pInfos = methodInfo.GetParameters(); if (pInfos != null && pInfos.Length > 0) { for (int i = 0; i < pInfos.Length; i++) { ParameterInfo p = pInfos[i]; parTypes.Add(p.ParameterType); if (p.ParameterType.IsByRef) { if (p.IsOut) { parOutIndex.Add(i); } else { parRefIndex.Add(i); } } else if (p.IsOptional && parDefaultStartIndex == -1) { parDefaultStartIndex = i; } } ParameterInfo lastP = pInfos[pInfos.Length - 1]; if (lastP.ParameterType.IsArray && lastP.IsDefined(typeof(ParamArrayAttribute), false)) { isParams = true; } } }
public CSToLuaConstructorRegister(CSToLuaClassRegister cr, ConstructorInfo[] ci) { classRegister = cr; constructorInfo = ci; }