nandi/vflutter_ffipublic Fork 0
claude/ssh-key-rickub-25a7d3
Commits
Clone
git clone https://git.rickub.com/nandi/vflutter_ffi.git
git clone ssh://git@rickub.com/nandi/vflutter_ffi.git

Host key fingerprint (ed25519): SHA256:iycHnxEyq0Q7uyVpB7JlznP0G7JrTPXLYRcAU5CSLhc — verify it before your first connect.

Initial commit: V -> Flutter FFI plugin ad0ccda · on claude/ssh-key-rickub-25a7d3 · nandi · 5h ago
vflutter.v · 43 lines · 1.3 KBCoq Blame HistoryRaw
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
module main

// ---------------------------------------------------------------------------
// C-ABI surface consumed by Dart FFI.
//
// Rules for everything below:
//   * only C-compatible types cross the boundary (int, f64, &char, voidptr)
//   * V strings/arrays/options/sumtypes never cross; convert first
//   * anything V allocates and hands out is released by vf_free
// ---------------------------------------------------------------------------

// Touches the V runtime so the GC and global initialisers are demonstrably
// live. The ELF/Mach-O constructor emitted by `v -shared` already does this;
// this exists for static-archive builds (iOS) where the caller wants a
// guaranteed, idempotent entry point.
@[export: 'vf_init']
fn vf_init() {
	probe := 'vf'
	_ = probe.len
}

@[export: 'vf_add']
fn vf_add(a int, b int) int {
	return a + b
}

// Returns a V-allocated C string. Caller releases it with vf_free.
//
// Built with `-gc none`, so every intermediate V allocation here must be
// freed by hand. Only the returned buffer outlives the call.
@[export: 'vf_greet']
fn vf_greet(name &char) &char {
	n := unsafe { cstring_to_vstring(name) }
	res := 'Hello, ${n}, from V!'
	out := unsafe { res.str }
	unsafe { n.free() }
	return out
}

@[export: 'vf_free']
fn vf_free(p voidptr) {
	unsafe { free(p) }
}