blob: 1c100e9dfdae7a1e980a74c5f337502d93fdf7a2 (
plain)
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
44
45
46
47
48
49
|
(* automatically generated by ocaml-bindgen 0.0.1 *)
type lifetime =
| Function
(** The value can live for the lifetime of the function call, which upon return will signal that the
value can be dropped (finalizer?) *)
| Ocaml (** The value is managed by the OCaml runtime *)
| C
(** The value is allocated and passed to C which is then in charge of cleaning it up *)
type 'a cptr = { lifetime : lifetime; addr : nativeint }
external bindgen_alloc : size:int -> nativeint = "bindgen_alloc"
external bindgen_free : nativeint -> unit = "bindgen_free"
external bindgen_alloc_string : string -> nativeint = "bindgen_alloc_string"
let sizeof _ = 4 (* TODO: how to handle different types? *)
let create_ptr (value : 'a) : 'a cptr =
let addr = bindgen_alloc ~size:(sizeof value) in
print_endline ("Addr: " ^ Nativeint.to_string addr);
Gc.finalise bindgen_free addr;
{ lifetime = Ocaml; addr }
let make_cstr (s: string) : char cptr =
let addr = bindgen_alloc_string s in
{ lifetime = Ocaml; addr }
type nonrec core
type nonrec glfwwindow
external get_global_core : unit -> core cptr = "caml_get_global_core"
external core_Bringup :
optional_window:unit cptr -> unit = "caml_core_Bringup"
external frame_Begin : unit -> unit = "caml_frame_Begin"
external frame_Draw : unit -> unit = "caml_frame_Draw"
external frame_End : unit -> unit = "caml_frame_End"
type nonrec vec2 = {
x: float ;
y: float }
type nonrec vec3 = {
x: float ;
y: float ;
z: float }
type nonrec vec4 = {
x: float ;
y: float ;
z: float ;
w: float }
external vec3_add : b:vec3 -> a:vec3 -> vec3 = "caml_vec3_add"
|