Mercurial > projects > qtd
comparison d2/qtd/Core.d @ 359:2013af5d0627
Aded Core.d
author | Max Samukha <maxter@spambox.com> |
---|---|
date | Wed, 02 Jun 2010 23:19:44 +0300 |
parents | |
children | 49d0a43433e7 |
comparison
equal
deleted
inserted
replaced
358:a3f5c10414f3 | 359:2013af5d0627 |
---|---|
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 /** | |
26 Defines a function that can be called from QtD C++ libraries, | |
27 which will register the function with the DLL at program startup. | |
28 */ | |
29 string qtdExport(string retType, string name, string args, string funcBody) | |
30 { | |
31 string ret; | |
32 version (cpp_shared) // TODO: cpp_shared implies Windows, which is not correct | |
33 { | |
34 // TODO: hackery to workaround a dmd/optlink bug corrupting symbol names | |
35 // when a direct function pointer export is used | |
36 ret ~= format_ctfe( | |
37 " ${4} ${0} qtd_export_${1}(${2}) { ${3} }\n" | |
38 " ${4} export void qtd_set_${1}(VoidFunc func);\n" | |
39 " static this() { qtd_set_${1}(cast(VoidFunc)&qtd_export_${1}); }\n", | |
40 retType, name, args, funcBody, qtdExtern); | |
41 } | |
42 else | |
43 { | |
44 ret = format_ctfe( | |
45 "${4} ${0} qtd_${1}(${2}) { ${3} }\n", | |
46 retType, name, args, funcBody, qtdExtern); | |
47 } | |
48 | |
49 return ret; | |
50 } |