add python runme
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@5648 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
19f7861039
commit
66c14bc75a
2 changed files with 17 additions and 10 deletions
7
SWIG/Examples/test-suite/python/wrapmacro_runme.py
Normal file
7
SWIG/Examples/test-suite/python/wrapmacro_runme.py
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
import wrapmacro
|
||||
|
||||
a = 2
|
||||
b = -1
|
||||
wrapmacro.max(a,b)
|
||||
wrapmacro.max(a/7.0, -b*256)
|
||||
wrapmacro.GUINT16_SWAP_LE_BE_CONSTANT(1)
|
||||
|
|
@ -1,22 +1,25 @@
|
|||
%module wrapmacro
|
||||
|
||||
/* Testing techniques for wrapping macros *
|
||||
/* Testing technique for wrapping macros */
|
||||
|
||||
|
||||
/* Here, some macros to wrap */
|
||||
%{
|
||||
#define guint16 int
|
||||
%inline %{
|
||||
|
||||
typedef unsigned short guint16;
|
||||
|
||||
#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;
|
||||
%rename(name) SWIGMACRO_##name;
|
||||
%inline %{
|
||||
type SWIGMACRO_##name(lparams) {
|
||||
return name(lnames);
|
||||
|
|
@ -29,19 +32,16 @@ type SWIGMACRO_##name(lparams) {
|
|||
|
||||
/* 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(size_t, max, PLIST(size_t a, const size_t& 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:
|
||||
/* 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'.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue