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)
	C.sqlite3_step(stmt)
	nr_users := C.sqlite3_column_int(stmt, 0)
	C.sqlite3_finalize(stmt)
	println(nr_users)
}

// 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 -DCIMGUI_DEFINE_ENUMS_AND_STRUCTS=1
#flag linux -DIMGUI_DISABLE_OBSOLETE_FUNCTIONS=1
#flag linux -DIMGUI_IMPL_API=