MCPcopy Create free account
hub / github.com/StereoKit/StereoKit / BuildRawFunction

Method BuildRawFunction

tools/StereoKitAPIGen/CSharp/CSModule.cs:19–63  ·  view source on GitHub ↗
(StringBuilder fnText, Dictionary<string, string> delegateText, CppFunction fn)

Source from the content-addressed store, hash-verified

17 ///////////////////////////////////////////
18
19 static void BuildRawFunction(StringBuilder fnText, Dictionary<string, string> delegateText, CppFunction fn)
20 {
21 SKType returnType = CSTypes.TypeName(fn.ReturnType, "", null);
22 SKTextType textType = returnType.text;
23
24 string line = $"{returnType.RawName,-20}{fn.Name,-20}(";
25 bool first = true;
26 int i = 0;
27 foreach (var p in fn.Parameters)
28 {
29 if (first) { first = false; }
30 else { line += ", "; }
31 SKType paramType;
32
33 // Something kinda weird happening here with function pointer
34 // params, but this code seems to work just fine.
35 if (p.Type.TypeKind == CppTypeKind.Pointer && ((CppPointerType)p.Type).ElementType.TypeKind == CppTypeKind.Function)
36 {
37 CppFunctionType fnParam = (CppFunctionType)((CppPointerType)p.Type).ElementType;
38 CppParameter subParam = fnParam.Parameters[i];
39 paramType = CSTypes.TypeName(subParam.Type, subParam.Name, delegateText);
40 if (paramType.fixedArray != 0) line += $"[MarshalAs(UnmanagedType.LPArray, SizeConst = {paramType.fixedArray})] ";
41 line += $"{paramType.RawName} {subParam.Name}";
42 }
43 else
44 {
45 paramType = CSTypes.TypeName(p.Type, p.Name, delegateText);
46 if (paramType.fixedArray != 0) line += $"[MarshalAs(UnmanagedType.LPArray, SizeConst = {paramType.fixedArray})] ";
47 line += $"{paramType.RawName} {p.Name}";
48 }
49 if (paramType.text != SKTextType.None) textType = paramType.text;
50 i+=1;
51 }
52 line += ");";
53
54 string charSet = textType switch
55 {
56 SKTextType.None => "",
57 SKTextType.Ascii => ", CharSet = ascii",
58 SKTextType.Utf8 => "",
59 SKTextType.Utf16 => ", CharSet = utf16",
60 };
61 line = $"[DllImport(dll, CallingConvention = call{charSet,-17})] public static extern " + line;
62 fnText.AppendLine(line);
63 }
64
65 ///////////////////////////////////////////
66

Callers

nothing calls this directly

Calls 1

TypeNameMethod · 0.80

Tested by

no test coverage detected