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()); }
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()); }
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()); }
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()); }
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()); }