1 %module wrapmacro
2 
3 #ifdef SWIGLUA	// lua only has one numeric type, so some overloads shadow each other creating warnings
4 %warnfilter(SWIGWARN_LANG_OVERLOAD_SHADOW) SWIGMACRO_maximum;
5 #endif
6 
7 /* Testing technique for wrapping macros */
8 
9 %{
10 #ifdef max
11 #undef max
12 #endif
13 %}
14 
15 /* Here, some macros to wrap */
16 %inline %{
17 
18 typedef unsigned short guint16;
19 
20 #define GUINT16_SWAP_LE_BE_CONSTANT(val) ((guint16) ( \
21     (guint16) ((guint16) (val) >> 8) |  \
22     (guint16) ((guint16) (val) << 8)))
23 
24 /* Don't use max(), it's a builtin function for PHP. */
25 #define maximum(a,b) ((a) > (b) ? (a) : (b))
26 
27 %}
28 
29 
30 /* Here, the auxiliary macro to wrap a macro */
31 %define %wrapmacro(type, name, lparams, lnames)
32 %rename(name) SWIGMACRO_##name;
33 %inline %{
name(lparams)34 type SWIGMACRO_##name(lparams) {
35   return name(lnames);
36 }
37 %}
38 %enddef
39 #define PLIST(...) __VA_ARGS__
40 
41 
42 
43 /* Here, wrapping the macros */
44 %wrapmacro(guint16, GUINT16_SWAP_LE_BE_CONSTANT, guint16 val, val);
45 %wrapmacro(size_t, maximum, PLIST(size_t a, const size_t& b), PLIST(a, b));
46 %wrapmacro(double, maximum, PLIST(double a, double b), PLIST(a, b));
47 
48 
49 /* Maybe in the future, a swig directive will make this easier:
50 
51 #define max(a,b) ((a) > (b) ? (a) : (b))
52 
53 %wrapmacro double max(long a, double b); // target name is 'max'
54 %wrapmacro(max_i) int max(int a, int b); // changes target name to 'max_i'.
55 
56 */
57 
58 %{
59 #ifdef max
60 #undef max
61 #endif
62 %}
63