import cffi ffi = cffi.FFI() ffi.set_source("_opengl", None) ffi.cdef(""" void glEnable(GLenum cap); void glClearColor(GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha); void glClear(GLbitfield mask); """) if __name__ == "__main__": ffi.compile()
import cffi ffi = cffi.FFI() ffi.set_source("_sqlite3", None) ffi.cdef(""" typedef struct sqlite3 sqlite3; typedef int (*sqlite3_callback)(void *, int, char **, char **); int sqlite3_open(const char *filename, sqlite3 **ppDb); int sqlite3_exec(sqlite3*, const char *sql, sqlite3_callback, void*, char **errmsg); int sqlite3_close(sqlite3*); """) if __name__ == "__main__": ffi.compile()This code defines the functions `sqlite3_open`, `sqlite3_exec`, and `sqlite3_close` from the SQLite library using `ffi.cdef`. The `ffi.set_source` function is used to provide the name of the generated C code, which will be used by the linker to build the final binary. Finally, the `ffi.compile` method is used to generate the C code.