Language Interop

Language Interoperability

Examples in V
#flag -lsqlite3
#include "sqlite3.h"

struct C.sqlite3
struct C.sqlite3_stmt

fn C.sqlite3_column_int(stmt C.sqlite3_stmt, n int) int

fn main() {
	path := 'users.db'
	db := &C.sqlite3{!} // a temporary hack meaning `sqlite3* db = 0`
	C.sqlite3_open(path.str, &db)
	query := 'select count(*) from users'
	stmt := &C.sqlite3_stmt{!}
	C.sqlite3_prepare_v2(db, query.str, - 1, &stmt, 0)
	nr_users := C.sqlite3_column_int(stmt, 0)

// Add #flag directives to the top of your V files to provide C compilation flags like -l for linking, -I for adding include files locations, -D for setting compile time variables, etc.
// You can use different flags for different targets. Right now, linux , darwin , and windows are supported.
// For now you have to use one flag per line:

#flag linux -lsdl2
#flag linux -Ivig
#flag linux -DIMGUI_IMPL_API=