summaryrefslogtreecommitdiff
path: root/Lib/d/dstrings.swg
diff options
context:
space:
mode:
authorDavid Nadlinger <code@klickverbot.at>2010-11-18 00:24:02 +0000
committerDavid Nadlinger <code@klickverbot.at>2010-11-18 00:24:02 +0000
commit03aefbc6e95d094a6de231e1f5264c0946e209a3 (patch)
tree94dff73a4aa3c27366f29f36712bde78317c5776 /Lib/d/dstrings.swg
parenta355d2d46af56c655816c37f24bb59fa6bade43f (diff)
downloadswig-03aefbc6e95d094a6de231e1f5264c0946e209a3.tar.gz
Added support for the D programming languge.
It is still a bit rough around some edges, particularly with regard to multi-threading and operator overloading, and there are some documentation bits missing, but it should be fine for basic use. The test-suite should build and run fine with the current versions of DMD, LDC and Tango (at least) on Linux x86_64 and Mac OS X 10.6. git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12299 626c5289-ae23-0410-ae9c-e8d60b6d4f22
Diffstat (limited to 'Lib/d/dstrings.swg')
-rw-r--r--Lib/d/dstrings.swg80
1 files changed, 80 insertions, 0 deletions
diff --git a/Lib/d/dstrings.swg b/Lib/d/dstrings.swg
new file mode 100644
index 000000000..a145c8d75
--- /dev/null
+++ b/Lib/d/dstrings.swg
@@ -0,0 +1,80 @@
+/* -----------------------------------------------------------------------------
+ * dstrings.swg
+ *
+ * Typemaps for wrapping pointers to/arrays of C chars as D strings.
+ * ----------------------------------------------------------------------------- */
+
+%define SWIGD_STRING_TYPEMAPS(DW_STRING_TYPE, DP_STRING_TYPE, FROM_STRINGZ, TO_STRINGZ)
+%typemap(cwtype) char *, char *&, char[ANY], char[] "char *"
+%typemap(dwtype) char *, char *&, char[ANY], char[] #DW_STRING_TYPE
+%typemap(dptype) char *, char *&, char[ANY], char[] #DP_STRING_TYPE
+
+
+/*
+ * char* typemaps.
+ */
+
+%typemap(in) char * %{ $1 = ($1_ltype)$input; %}
+%typemap(out) char * %{ $result = SWIG_d_string_callback((const char *)$1); %}
+%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) char * %{ $result = ($1_ltype)$input; %}
+%typemap(directorin) char * %{ $input = SWIG_d_string_callback((const char *)$1); %}
+%typemap(ddirectorin) char * "FROM_STRINGZ($winput)"
+%typemap(ddirectorout) char * "TO_STRINGZ($dpcall)"
+
+
+/*
+ * char*& typemaps.
+ */
+
+%typemap(in) char *& ($*1_ltype temp = 0) %{
+ temp = ($*1_ltype)$input;
+ $1 = &temp;
+%}
+%typemap(out) char *& %{ if ($1) $result = SWIG_d_string_callback((const char *)*$1); %}
+
+
+/*
+ * char array typemaps.
+ */
+
+%typemap(in) char[ANY], char[] %{ $1 = ($1_ltype)$input; %}
+%typemap(out) char[ANY], char[] %{ $result = SWIG_d_string_callback((const char *)$1); %}
+
+%typemap(directorout) char[ANY], char[] %{ $result = ($1_ltype)$input; %}
+%typemap(directorin) char[ANY], char[] %{ $input = SWIG_d_string_callback((const char *)$1); %}
+
+%typemap(ddirectorin) char[ANY], char[] "$winput"
+%typemap(ddirectorout) char[ANY], char[] "$dpcall"
+
+
+%typemap(din) char *, char *&, char[ANY], char[] "($dinput ? TO_STRINGZ($dinput) : null)"
+%typemap(dout, excode=SWIGEXCODE) char *, char *&, char[ANY], char[] {
+ DP_STRING_TYPE ret = FROM_STRINGZ ## ($wcall);$excode
+ return ret;
+}
+
+%typecheck(SWIG_TYPECHECK_STRING)
+ char *,
+ char *&,
+ char[ANY],
+ char[]
+ ""
+%enddef
+
+
+// We need to have the \0-terminated string conversion functions available in
+// the D proxy modules.
+#if (SWIG_D_VERSION == 1)
+// Could be easily extended to support Phobos as well.
+SWIGD_STRING_TYPEMAPS(char*, char[], tango.stdc.stringz.fromStringz, tango.stdc.stringz.toStringz)
+
+%pragma(d) globalproxyimports = "static import tango.stdc.stringz;";
+#else
+SWIGD_STRING_TYPEMAPS(const(char)*, string, std.conv.to!string, std.string.toStringz)
+
+%pragma(d) globalproxyimports = %{
+static import std.conv;
+static import std.string;
+%}
+#endif
+#undef SWIGD_STRING_TYPEMAPS