359
|
1 module qtd.Core;
|
|
2
|
|
3 import
|
|
4 qtd.ctfe.Format,
|
|
5 std.stdio;
|
|
6
|
|
7 T static_cast(T, U)(U obj)
|
|
8 {
|
|
9 return cast(T)cast(void*)obj;
|
|
10 }
|
|
11
|
|
12 enum qtdExtern = "extern (C)";
|
|
13
|
|
14 extern(C) alias void function() VoidFunc;
|
|
15 extern(C) void qtd_initCore();
|
|
16
|
|
17 immutable Object qtdMoLock;
|
|
18
|
|
19 static this()
|
|
20 {
|
|
21 qtdMoLock = cast(immutable)new Object;
|
|
22 qtd_initCore();
|
|
23 }
|
|
24
|
|
25 /**
|
360
|
26 Defines a function that can be called from QtD C++ libraries.
|
|
27 The function will be automatically
|
|
28 registered with the DLL at program startup.
|
359
|
29 */
|
|
30 string qtdExport(string retType, string name, string args, string funcBody)
|
|
31 {
|
|
32 string ret;
|
|
33 version (cpp_shared) // TODO: cpp_shared implies Windows, which is not correct
|
|
34 {
|
|
35 // TODO: hackery to workaround a dmd/optlink bug corrupting symbol names
|
|
36 // when a direct function pointer export is used
|
|
37 ret ~= format_ctfe(
|
|
38 " ${4} ${0} qtd_export_${1}(${2}) { ${3} }\n"
|
|
39 " ${4} export void qtd_set_${1}(VoidFunc func);\n"
|
|
40 " static this() { qtd_set_${1}(cast(VoidFunc)&qtd_export_${1}); }\n",
|
|
41 retType, name, args, funcBody, qtdExtern);
|
|
42 }
|
|
43 else
|
|
44 {
|
|
45 ret = format_ctfe(
|
|
46 "${4} ${0} qtd_${1}(${2}) { ${3} }\n",
|
|
47 retType, name, args, funcBody, qtdExtern);
|
|
48 }
|
|
49
|
|
50 return ret;
|
|
51 }
|