summaryrefslogtreecommitdiff
path: root/demo/embedding.py
blob: f20b4e4221afc23433927dd4a32ce7e2ad27380e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import cffi

ffi = cffi.FFI()

ffi.cdef("""
    extern "Python" {
        int add(int, int);
    }
""", dllexport=True)

ffi.embedding_init_code("""
    from _embedding_cffi import ffi
    print "preparing"   # printed once

    @ffi.def_extern()
    def add(x, y):
        print "adding", x, "and", y
        return x + y
""")

ffi.set_source("_embedding_cffi", "")

ffi.compile(verbose=True)