1 /**
2    Types to be used in the API for type-safety
3    (as opposed to, say, raw strings).
4  */
5 module autowrap.types;
6 
7 
8 template isModule(alias T) {
9     import std.traits: Unqual;
10     enum isModule = is(Unqual!(typeof(T)) == Module);
11 }
12 
13 
14 /**
15    The list of modules to automatically wrap for consumption by other languages.
16  */
17 struct Modules {
18     import std.traits: Unqual;
19     import std.meta: allSatisfy;
20 
21     Module[] value;
22 
23     this(A...)(auto ref A modules) {
24 
25         foreach(module_; modules) {
26             static if(is(Unqual!(typeof(module_)) == Module))
27                 value ~= module_;
28             else static if(is(Unqual!(typeof(module_)) == string))
29                 value ~= Module(module_);
30             else
31                 static assert(false, "Modules must either be `string` or `Module`");
32         }
33     }
34 }
35 
36 /**
37    A module to automatically wrap.
38    Usually not needed since a string will do, but is useful when trying to export
39    all functions from a module by using Module("mymodule", Yes.alwaysExport)
40    instead of "mymodule"
41  */
42 struct Module {
43     import std.typecons: Flag, No;
44 
45     string name;
46     Flag!"alwaysExport" alwaysExport = No.alwaysExport;
47 
48     string toString() @safe pure const {
49         import std.conv: text;
50         import std.string: capitalize;
51         return text(`Module("`, name, `", `, text(alwaysExport).capitalize, `.alwaysExport)`);
52     }
53 }
54 
55 
56 /**
57    The name of the dynamic library, i.e. the file name with the .so/.dll extension
58  */
59 struct LibraryName {
60     string value;
61 }
62 
63 /**
64    Code to be inserted before the call to module_init
65  */
66 struct PreModuleInitCode {
67     string value;
68 }
69 
70 /**
71    Code to be inserted after the call to module_init
72  */
73 struct PostModuleInitCode {
74     string value;
75 }
76 
77 
78 struct RootNamespace {
79     string value;
80 }
81 
82 struct OutputFileName {
83     string value;
84 }