python - Preprocessor macro in SWIG -


I'm trying to get SWIG to recognize a simple preprocessor macro which is based on another definition The new function "defines" and more complex tasks, therefore, in the C header file I have:

  #define FOO1 # my_macro_fun (args) my_fun (args, FOO)   

SWIG sees and successfully wraps up my_fun , but I want to wrap it up with my_macro_fun .

tries to place SWIG and wrap them, but it does anything with that kind of macro will not be able to. Fortunately, there is almost a simple job. Imagine you have the following header file:

  #define FOO1 # my_macro_fun (args) my_fun (args, FOO) zero my_fun (int a, int b);   

You can wrap it like this:

 % include the module exam% {# "test.h"%} "test.h "Include   

which leaves the my_macro_fun function. To wrap SWIG that although you need to:

 % include the module exam% {# "test.h"%} //! Tell SWIG that it should be wrapped like any other function. Zero my_macro_fun (int); // It is completely optional: Because of my wrapping up my_fun, add% well "test.h"   

This little lie is absolutely fine in SWIG - this wrapper Code will assume that my_macro_fun (int) is callable, absolutely fine as if you were using macros. When compiling the cover, the compiler will end using the macro and no one will be intelligent.

Note that the order is important - the function that really needs to come before the % in the interface file otherwise SWIG will expand the macro during the parsing of your announcement. Which will attempt to create a syntax error. If you want to include it for other parts, but press Basic my_fun , then you can leave % include or % ignore < / Code>. In the generated interface. You can also do this with some SWIG languages ​​(for example Python):

 % module exam% {# # "test.h" % Include}% temp (default) int b {$ 1 = FOO; } Include% "test.h"   

To provide a value for the argument, if none has been given for it.

Comments