diff options
author | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-07-28 00:10:00 +1000 |
---|---|---|
committer | omniscient <17525998+omnisci3nce@users.noreply.github.com> | 2024-07-28 00:10:00 +1000 |
commit | 7b86e3251a28406862fe16d49f8533beb8ca3150 (patch) | |
tree | a90166418ada7ad88500843ce8881a453c1d4721 /bindgen/ocaml/bindings/bindings_sys.ml | |
parent | 6b004c5ac6a25f1020774276803b62e8619ea61e (diff) |
start on ocaml bindings
Diffstat (limited to 'bindgen/ocaml/bindings/bindings_sys.ml')
-rw-r--r-- | bindgen/ocaml/bindings/bindings_sys.ml | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/bindgen/ocaml/bindings/bindings_sys.ml b/bindgen/ocaml/bindings/bindings_sys.ml new file mode 100644 index 0000000..1c100e9 --- /dev/null +++ b/bindgen/ocaml/bindings/bindings_sys.ml @@ -0,0 +1,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" |