Mercurial > projects > qtd
changeset 359:2013af5d0627
Aded Core.d
author | Max Samukha <maxter@spambox.com> |
---|---|
date | Wed, 02 Jun 2010 23:19:44 +0300 |
parents | a3f5c10414f3 |
children | 49d0a43433e7 |
files | d2/qtd/Core.d |
diffstat | 1 files changed, 50 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/d2/qtd/Core.d Wed Jun 02 23:19:44 2010 +0300 @@ -0,0 +1,50 @@ +module qtd.Core; + +import + qtd.ctfe.Format, + std.stdio; + +T static_cast(T, U)(U obj) +{ + return cast(T)cast(void*)obj; +} + +enum qtdExtern = "extern (C)"; + +extern(C) alias void function() VoidFunc; +extern(C) void qtd_initCore(); + +immutable Object qtdMoLock; + +static this() +{ + qtdMoLock = cast(immutable)new Object; + qtd_initCore(); +} + +/** + Defines a function that can be called from QtD C++ libraries, + which will register the function with the DLL at program startup. + */ +string qtdExport(string retType, string name, string args, string funcBody) +{ + string ret; + version (cpp_shared) // TODO: cpp_shared implies Windows, which is not correct + { + // TODO: hackery to workaround a dmd/optlink bug corrupting symbol names + // when a direct function pointer export is used + ret ~= format_ctfe( + " ${4} ${0} qtd_export_${1}(${2}) { ${3} }\n" + " ${4} export void qtd_set_${1}(VoidFunc func);\n" + " static this() { qtd_set_${1}(cast(VoidFunc)&qtd_export_${1}); }\n", + retType, name, args, funcBody, qtdExtern); + } + else + { + ret = format_ctfe( + "${4} ${0} qtd_${1}(${2}) { ${3} }\n", + retType, name, args, funcBody, qtdExtern); + } + + return ret; +}