summaryrefslogtreecommitdiff
path: root/Examples/test-suite/wrapmacro.i
diff options
context:
space:
mode:
authorMarcelo Matus <mmatus@acms.arizona.edu>2004-01-17 00:56:31 +0000
committerMarcelo Matus <mmatus@acms.arizona.edu>2004-01-17 00:56:31 +0000
commitfe460c4c53edec8300ce9f08c2cbb20ed945f2f7 (patch)
tree119ef23b4bf91b2c58f7a99c4656d3eb90e4436b /Examples/test-suite/wrapmacro.i
parentdde72e892fe9c576d2f6fc57df1e9364f8395ecb (diff)
downloadswig-fe460c4c53edec8300ce9f08c2cbb20ed945f2f7.tar.gz
add file to test macro wrapping techniques
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5641 626c5289-ae23-0410-ae9c-e8d60b6d4f22
Diffstat (limited to 'Examples/test-suite/wrapmacro.i')
-rw-r--r--Examples/test-suite/wrapmacro.i47
1 files changed, 47 insertions, 0 deletions
diff --git a/Examples/test-suite/wrapmacro.i b/Examples/test-suite/wrapmacro.i
new file mode 100644
index 000000000..ca7e64e13
--- /dev/null
+++ b/Examples/test-suite/wrapmacro.i
@@ -0,0 +1,47 @@
+%module wrapmacro
+
+/* Testing techniques for wrapping macros *
+
+
+/* Here, some macros to wrap */
+%{
+#define guint16 int
+#define GUINT16_SWAP_LE_BE_CONSTANT(val) ((guint16) ( \
+ (guint16) ((guint16) (val) >> 8) | \
+ (guint16) ((guint16) (val) << 8)))
+
+#define max(a,b) ((a) > (b) ? (a) : (b))
+
+%}
+
+/* Here, the auxiliar macro to wrap a macro */
+%define %wrapmacro(type, name, lparams, lnames)
+%rename(SWIGMACRO_##name) name;
+%inline %{
+type SWIGMACRO_##name(lparams) {
+ return name(lnames);
+}
+%}
+%enddef
+#define PLIST(...) __VA_ARGS__
+
+
+
+/* Here, wrapping the macros */
+%wrapmacro(guint16, GUINT16_SWAP_LE_BE_CONSTANT, guint16 val, val);
+%wrapmacro(int, max, PLIST(int a, int b), PLIST(a, b));
+%wrapmacro(double, max, PLIST(double a, double b), PLIST(a, b));
+
+
+/*
+
+Maybe in the future, a swig directive will do this easier:
+
+#define max(a,b) ((a) > (b) ? (a) : (b))
+
+%wrapmacro double max(long a, double b); // target name is 'max'
+%wrapmacro(max_i) int max(int a, int b); // changes target name to 'max_i'.
+
+
+*/
+