1
# examples/increment_example.py
3
#from weave import ext_tools
5
# use the following so that development version is used.
7
sys.path.insert(0,'..')
10
def build_increment_ext():
11
""" Build a simple extension with functions that increment numbers.
12
The extension will be built in the local directory.
14
mod = ext_tools.ext_module('increment_ext')
16
a = 1 # effectively a type declaration for 'a' in the
17
# following functions.
19
ext_code = "return_val = PyInt_FromLong(a+1);"
20
func = ext_tools.ext_function('increment',ext_code,['a'])
21
mod.add_function(func)
23
ext_code = "return_val = PyInt_FromLong(a+2);"
24
func = ext_tools.ext_function('increment_by_2',ext_code,['a'])
25
mod.add_function(func)
29
if __name__ == "__main__":
36
print 'a, a+1:', a, increment_ext.increment(a)
37
print 'a, a+2:', a, increment_ext.increment_by_2(a)