#!/usr/bin/env python

from awesome_new_c_binding_thingy import c_function, In, Out, Error, c_int, c_int_ptr

# this decorated, annotated Python function has all the information necessesary
# to create the below bindings code, either ahead of time or just in time, etc
@c_function('example.h', 'libraryname')
def foo(x: In[c_int], y: In[c_int], result: Out[c_int_ptr]) -> Error[c_int]:
    pass


#
# Magically generated code
#

from cffi import FFI
ffi = FFI()

ffi.cdef('''\
int foo(int x, int y, int* result);
''')

lib = ffi.verify(r'''\
#include <example.h>
''',
    libraries=['libraryname'],
)

def foo(x: int, y: int) -> int:
    result = ffi.new('int*')
    error = lib.foo(x, y, result)
    if error:
        raise RuntimeError('foo returned %d' % error)
    return result[0]