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

ffibuilder = cffi.FFI()

ffibuilder.embedding_api("""
    int add(int, int);
""")

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

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

ffibuilder.set_source("_embedding_cffi", "")

ffibuilder.compile(verbose=True)