• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import cffi
2
3ffi = cffi.FFI()
4
5ffi.embedding_api("""
6    int (*my_callback)(int);
7    int add_rec(int, int);
8""")
9
10ffi.embedding_init_code(r"""
11    from _add_recursive_cffi import ffi, lib
12    import sys
13    print("preparing REC")
14    sys.stdout.flush()
15
16    @ffi.def_extern()
17    def add_rec(x, y):
18        print("adding %d and %d" % (x, y))
19        sys.stdout.flush()
20        return x + y
21
22    x = lib.my_callback(400)
23    print('<<< %d >>>' % (x,))
24""")
25
26ffi.set_source("_add_recursive_cffi", """
27/* use CFFI_DLLEXPORT: on windows, it expands to __declspec(dllexport),
28   which is needed to export a variable from a dll */
29CFFI_DLLEXPORT int (*my_callback)(int);
30""")
31
32fn = ffi.compile(verbose=True)
33print('FILENAME: %s' % (fn,))
34