>>> import example
>>> example.fact(10)
Received an integer : 10
3628800
>>>
In the previous example, the typemap is applied to all occurrences of the „long“ datatype. We can refine this by supplying an optional parameter name. For example:
%typemap(in) long n { $1 = (long) PyLong_AsLong($input); if ($1 <= 0) PyErr_SetString(PyExc_ValueError,"Expected a positive value."); return NULL; } }
The typemap code will only be applied to arguments which exactly match „long n“ (not „long m“ e.g.)