static private GetMethodName ( MethodInfo md ) : string | ||
md | MethodInfo | |
return | string |
static void GenClassApi(ToLuaMenu.BindType bt) { Type type = bt.type; if (type.IsGenericType)//泛型类被tolua处理成全局库了,如果都加成api自动提示的时候反而不方便 { return; } //计算lua中的全局名和继承者 string name = bt.name; string inherits = null; if (bt.baseType != null && !bt.baseType.IsGenericType) { inherits = ToLuaExport.GetBaseTypeStr(bt.baseType); } //创建api类 var api = GetClassApi(name, inherits); string returns = null, valueType = null; //注册成员函数,参考的是ToLuaExport.GenRegisterFuncItems for (int i = 0; i < ToLuaExport.methods.Count; i++) { MethodInfo m = ToLuaExport.methods[i].Method as MethodInfo; int count = 1; string methodName = ToLuaExport.GetMethodName(m); if (ToLuaExport.nameCounter.TryGetValue(methodName, out count)) { ToLuaExport.nameCounter[methodName] = count + 1; continue; } ToLuaExport.nameCounter[methodName] = 1; if (m.IsGenericMethod || methodName == "set_Item" || methodName == "get_Item" || methodName.StartsWith("op_")) { continue; } //获取返回值信息 GetReturnTypeStr(m.ReturnType, ref returns, ref valueType); //获取参数信息 ParameterInfo[] paramInfos = m.GetParameters(); s_paramName.Clear(); s_paramName.Append('('); for (int j = 0; j < paramInfos.Length; ++j) { s_paramName.Append(paramInfos[j].Name); if (j != paramInfos.Length - 1) { s_paramName.Append(','); } } s_paramName.Append(')'); string param = s_paramName.ToString(); if (m.IsStatic) { api.AddFunction(methodName, param, returns, valueType); } else { api.AddMethod(methodName, param, returns, valueType); } } //注册成员变量和属性 for (int i = 0; i < ToLuaExport.fields.Length; i++) { GetReturnTypeStr(ToLuaExport.fields[i].FieldType, ref returns, ref valueType); api.AddValue(ToLuaExport.fields[i].Name, valueType); } for (int i = 0; i < ToLuaExport.props.Length; i++) { GetReturnTypeStr(ToLuaExport.props[i].PropertyType, ref returns, ref valueType); api.AddValue(ToLuaExport.props[i].Name, valueType); } //注册操作符,暂时不需要 //注册构造函数,暂时不需要 //注册索引器,暂时不需要 }