1 module python.boilerplate;
2 
3 
4 import python.raw: isPython2, isPython3;
5 import std.traits: isFunction;
6 
7 
8 /// For a nicer API
9 struct Module {
10     string name;
11 }
12 
13 
14 /// For a nicer API
15 struct CFunctions(Args...) {
16 
17     import std.meta: staticMap;
18 
19     enum length = Args.length;
20 
21     private template toCFunction(alias F) {
22         static if(isFunction!F)
23             alias toCFunction = CFunction!F;
24         else
25             alias toCFunction = F;
26     }
27 
28     alias functions = staticMap!(toCFunction, Args);
29 
30     static string stringifySymbols() {
31         import std.array: join;
32 
33         string[] ret;
34 
35         static foreach(func; functions)
36             ret ~= `CFunction!(` ~ __traits(identifier, func.symbol) ~ `, "` ~ func.identifier ~ `")`;
37 
38         return ret.join(", ");
39     }
40 }
41 
42 /// For a nicer API
43 struct CFunction(alias F, string I = "") if(isFunction!F) {
44 
45     alias symbol = F;
46 
47     static if(I == "")
48         enum identifier = __traits(identifier, symbol);
49     else
50         enum
51             identifier = I;
52 }
53 
54 
55 /// A list of aggregates to wrap
56 struct Aggregates(T...) {
57     alias Types = T;
58 
59     static string stringifyTypes() {
60         import std.array: join;
61         string[] ret;
62 
63         static foreach(T; Types)
64             ret ~= T.stringof;
65 
66         return ret.join(", ");
67     }
68 }