| 43 | /////////////////////////////////////////// |
| 44 | |
| 45 | class CSTypes |
| 46 | { |
| 47 | public static string SnakeToCamel(string name, bool active, int removePrefix) |
| 48 | { |
| 49 | if (NameOverrides.TryGet(name, out string result)) |
| 50 | return result; |
| 51 | |
| 52 | string[] words = name.Substring(removePrefix).Split("_"); |
| 53 | if (words.Length > 1 && words[words.Length - 1] == "t") words[words.Length - 1] = ""; |
| 54 | for (int i = 0; i < words.Length; i++) |
| 55 | { |
| 56 | if ((i > 0 || active) && words[i].Length>0) |
| 57 | words[i] = char.ToUpper( words[i][0]) + words[i].Substring(1); |
| 58 | } |
| 59 | return string.Join("", words); |
| 60 | } |
| 61 | |
| 62 | /////////////////////////////////////////// |
| 63 | |
| 64 | public static string CallbackType(CppFunctionType fn, string varName) |
| 65 | { |
| 66 | bool isVoidRet = fn.ReturnType.TypeKind == CppTypeKind.Primitive && ((CppPrimitiveType)fn.ReturnType).Kind == CppPrimitiveKind.Void; |
| 67 | if (isVoidRet == true && fn.Parameters.Count == 0) |
| 68 | return "Action"; |
| 69 | |
| 70 | string result = SnakeToCamel(varName, true, 0); |
| 71 | |
| 72 | /*for (int i = 0; i < fn.Parameters.Count; i++) |
| 73 | { |
| 74 | var p = fn.Parameters[i]; |
| 75 | result += "_" + TypeName(p.Type, p.Name, null).raw; |
| 76 | }*/ |
| 77 | |
| 78 | return result; |
| 79 | } |
| 80 | |
| 81 | /////////////////////////////////////////// |
| 82 | |
| 83 | public static string CallbackDefinition(CppFunctionType fn, string varName) |
| 84 | { |
| 85 | bool isVoidRet = fn.ReturnType.TypeKind == CppTypeKind.Primitive && ((CppPrimitiveType)fn.ReturnType).Kind == CppPrimitiveKind.Void; |
| 86 | if (isVoidRet == true && fn.Parameters.Count == 0) |
| 87 | return ""; |
| 88 | |
| 89 | string ret = isVoidRet |
| 90 | ? "void" |
| 91 | : TypeName(fn.ReturnType, "", null).raw; |
| 92 | |
| 93 | string result = $"internal delegate {ret} {CallbackType(fn, varName)}("; |
| 94 | for (int i = 0; i < fn.Parameters.Count; i++) |
| 95 | { |
| 96 | if (i != 0) result += ", "; |
| 97 | |
| 98 | var p = fn.Parameters[i]; |
| 99 | result += TypeName(p.Type, p.Name, null).RawName + " " + SnakeToCamel(p.Name, false, 0); |
| 100 | } |
| 101 | result += ");"; |
| 102 |
nothing calls this directly
no outgoing calls
no test coverage detected