import source from 1.3.40
[external/swig.git] / Examples / test-suite / aggregate.i
1 /* This file tests a few new contract features.
2    First it checks to make sure the constant aggregation macro
3    %aggregate_check() works.  This is defined in swig.swg.
4
5    Next, it checks to make sure a simple contract works.
6    To support contracts, you need to add a macro to the runtime.
7    For Python, it looks like this:
8
9 #define SWIG_contract_assert(expr, msg)  if (!(expr)) { PyErr_SetString(PyExc_RuntimeError, (char *) msg #expr ); goto fail; } else
10
11    Note: It is used like this:
12    SWIG_contract_assert(x == 1, "Some kind of error message");
13
14    Note: Contracts are still experimental.  The runtime interface may
15    change in future versions.   
16    */
17
18 %module aggregate
19
20 %include <exception.i>
21 %aggregate_check(int, check_direction, UP, DOWN, LEFT, RIGHT)
22
23 %contract move(int x) {
24 require:
25    check_direction(x);
26 }
27
28 %inline %{
29 #define UP    1
30 #define DOWN  2
31 #define LEFT  3
32 #define RIGHT 4
33
34 int move(int direction) {
35     return direction;
36 }
37 %}