summaryrefslogtreecommitdiff
path: root/demo
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2015-11-30 16:45:46 +0100
committerArmin Rigo <arigo@tunes.org>2015-11-30 16:45:46 +0100
commitcb999cd1b28d01a81f994ce4798acec7a4086d4a (patch)
tree249a44644f918df6c12d5f7dcd3ac143819630e2 /demo
parent3bfbf9a79e0d5f8c88ea8fad0cc054ccd6f0bd90 (diff)
downloadcffi-cb999cd1b28d01a81f994ce4798acec7a4086d4a.tar.gz
"embedding" mode, where we produce a .so with the given C API
usable from a non-Python-aware program
Diffstat (limited to 'demo')
-rw-r--r--demo/embedding.py19
-rw-r--r--demo/embedding_test.c17
2 files changed, 36 insertions, 0 deletions
diff --git a/demo/embedding.py b/demo/embedding.py
new file mode 100644
index 0000000..4e3d71c
--- /dev/null
+++ b/demo/embedding.py
@@ -0,0 +1,19 @@
+import cffi
+
+ffi = cffi.FFI()
+
+ffi.export_cdef("""
+ extern "Python" int add(int, int);
+""", """
+ from _embedding_cffi import ffi, lib
+
+ @ffi.def_extern()
+ def add(x, y):
+ print "adding", x, "and", y
+ return x + y
+""")
+
+ffi.set_source("libembedding_test", """
+""")
+
+ffi.compile()
diff --git a/demo/embedding_test.c b/demo/embedding_test.c
new file mode 100644
index 0000000..39c6e26
--- /dev/null
+++ b/demo/embedding_test.c
@@ -0,0 +1,17 @@
+/* Link this program with libembedding_test.so.
+ E.g. with gcc:
+
+ gcc -o embedding_test embedding_test.c -L. -lembedding_test
+*/
+
+#include <stdio.h>
+
+extern int add(int x, int y);
+
+
+int main(void)
+{
+ int res = add(40, 2);
+ printf("result: %d\n", res);
+ return 0;
+}