add python runme
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@5648 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
parent
9030e12d3f
commit
10f3808329
2 changed files with 17 additions and 10 deletions
7
Examples/test-suite/python/wrapmacro_runme.py
Normal file
7
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,11 +1,13 @@
|
||||||
%module wrapmacro
|
%module wrapmacro
|
||||||
|
|
||||||
/* Testing techniques for wrapping macros *
|
/* Testing technique for wrapping macros */
|
||||||
|
|
||||||
|
|
||||||
/* Here, some macros to wrap */
|
/* Here, some macros to wrap */
|
||||||
%{
|
%inline %{
|
||||||
#define guint16 int
|
|
||||||
|
typedef unsigned short guint16;
|
||||||
|
|
||||||
#define GUINT16_SWAP_LE_BE_CONSTANT(val) ((guint16) ( \
|
#define GUINT16_SWAP_LE_BE_CONSTANT(val) ((guint16) ( \
|
||||||
(guint16) ((guint16) (val) >> 8) | \
|
(guint16) ((guint16) (val) >> 8) | \
|
||||||
(guint16) ((guint16) (val) << 8)))
|
(guint16) ((guint16) (val) << 8)))
|
||||||
|
|
@ -14,9 +16,10 @@
|
||||||
|
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|
||||||
/* Here, the auxiliar macro to wrap a macro */
|
/* Here, the auxiliar macro to wrap a macro */
|
||||||
%define %wrapmacro(type, name, lparams, lnames)
|
%define %wrapmacro(type, name, lparams, lnames)
|
||||||
%rename(SWIGMACRO_##name) name;
|
%rename(name) SWIGMACRO_##name;
|
||||||
%inline %{
|
%inline %{
|
||||||
type SWIGMACRO_##name(lparams) {
|
type SWIGMACRO_##name(lparams) {
|
||||||
return name(lnames);
|
return name(lnames);
|
||||||
|
|
@ -29,19 +32,16 @@ type SWIGMACRO_##name(lparams) {
|
||||||
|
|
||||||
/* Here, wrapping the macros */
|
/* Here, wrapping the macros */
|
||||||
%wrapmacro(guint16, GUINT16_SWAP_LE_BE_CONSTANT, guint16 val, val);
|
%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));
|
%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))
|
#define max(a,b) ((a) > (b) ? (a) : (b))
|
||||||
|
|
||||||
%wrapmacro double max(long a, double b); // target name is 'max'
|
%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'.
|
%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