summaryrefslogtreecommitdiff
path: root/demo
diff options
context:
space:
mode:
authorArmin Rigo <arigo@tunes.org>2015-11-16 11:52:55 +0100
committerArmin Rigo <arigo@tunes.org>2015-11-16 11:52:55 +0100
commit2a2034edc5f1e33c80da8d36957c30d7dc781c5c (patch)
treef5ed7165acfc344bc33e34fbf5dc14f98aed6eb9 /demo
parent5c8ea352daa42bfd20bcd1297032ecad044c35f3 (diff)
downloadcffi-2a2034edc5f1e33c80da8d36957c30d7dc781c5c.tar.gz
Add a minimal demo of CFFI_CALL_PYTHON
Diffstat (limited to 'demo')
-rw-r--r--demo/cdef_call_python.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/demo/cdef_call_python.py b/demo/cdef_call_python.py
new file mode 100644
index 0000000..24f420f
--- /dev/null
+++ b/demo/cdef_call_python.py
@@ -0,0 +1,29 @@
+import cffi
+
+ffi = cffi.FFI()
+
+ffi.cdef("""
+ int add(int x, int y);
+ CFFI_CALL_PYTHON long mangle(int);
+""")
+
+ffi.set_source("_cdef_call_python_cffi", """
+
+ static long mangle(int);
+
+ static int add(int x, int y)
+ {
+ return mangle(x) + mangle(y);
+ }
+""")
+
+ffi.compile()
+
+
+from _cdef_call_python_cffi import ffi, lib
+
+@ffi.call_python("mangle") # optional argument, default to func.__name__
+def mangle(x):
+ return x * x
+
+assert lib.add(40, 2) == 1604