Skip to content

Commit

Permalink
Add a third example using neither dlopen() nor verify().
Browse files Browse the repository at this point in the history
  • Loading branch information
arigo committed Jun 14, 2012
1 parent d709b71 commit 5064be1
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ Simple example (ABI level)
hi there, world!
>>>

Simple example (API level)
--------------------------
Real example (API level)
------------------------

from cffi import FFI
ffi = FFI()
Expand All @@ -64,8 +64,27 @@ Simple example (API level)
assert str(C.getpwuid(0).pw_name) == 'root'

Note that the above example works independently of the exact layout of
"struct passwd", but so far require a C compiler at runtime. (This will
be improved with caching and distribution of the compiled code.)
"struct passwd", but so far require a C compiler at runtime. (We plan
to improve with caching and a way to distribute the compiled code.)

Struct/Array Example
--------------------

from cffi import FFI
ffi = FFI()
ffi.cdef("""
typedef struct {
unsigned char r, g, b;
} pixel_t;
""")
image = ffi.new("pixel_t[]", 800*600)
image[0].r = 255
image[0].g = 192
image[0].b = 128

This can be used as a more flexible replacement of the struct_ and
array_ modules. You could also call ``ffi.new("pixel_t[600][800]")``
and get a two-dimensional array.


More documentation
Expand Down

0 comments on commit 5064be1

Please sign in to comment.