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