diff options
author | Armin Rigo <arigo@tunes.org> | 2016-01-12 19:03:48 +0100 |
---|---|---|
committer | Armin Rigo <arigo@tunes.org> | 2016-01-12 19:03:48 +0100 |
commit | e17e336286cfc65e04d8e12712c03e9c91b3e5ce (patch) | |
tree | e0b5ae3ff247e2ae6e0ef535b326f68b062722a0 /demo | |
parent | a367d1459c4f7cc1da501e069ebabfe3369b9c9b (diff) | |
parent | 2bb88c61a3a1bdec594604d2380c74728b7c1306 (diff) | |
download | cffi-e17e336286cfc65e04d8e12712c03e9c91b3e5ce.tar.gz |
hg merge default
Diffstat (limited to 'demo')
-rw-r--r-- | demo/embedding.py | 21 | ||||
-rw-r--r-- | demo/embedding_test.c | 19 |
2 files changed, 40 insertions, 0 deletions
diff --git a/demo/embedding.py b/demo/embedding.py new file mode 100644 index 0000000..40c419f --- /dev/null +++ b/demo/embedding.py @@ -0,0 +1,21 @@ +import cffi + +ffi = cffi.FFI() + +ffi.embedding_api(""" + int add(int, int); +""") + +ffi.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 +""") + +ffi.set_source("_embedding_cffi", "") + +ffi.compile(verbose=True) diff --git a/demo/embedding_test.c b/demo/embedding_test.c new file mode 100644 index 0000000..87d313b --- /dev/null +++ b/demo/embedding_test.c @@ -0,0 +1,19 @@ +/* Link this program with libembedding_test.so. + E.g. with gcc: + + gcc -o embedding_test embedding_test.c _embedding_cffi*.so +*/ + +#include <stdio.h> + +extern int add(int x, int y); + + +int main(void) +{ + int res = add(40, 2); + printf("result: %d\n", res); + res = add(100, -5); + printf("result: %d\n", res); + return 0; +} |