tjammer / raylib-ocaml

OCaml bindings for raylib and raygui
https://tjammer.github.io/raylib-ocaml/
MIT License
175 stars 14 forks source link

How do you call functions that expect a Ctypes.ptr? #18

Closed TyOverby closed 2 years ago

TyOverby commented 3 years ago

I want to call draw_line_strip which has type Raylib.Vector2.t Ctypes.ptr, but unless I'm missing something, it's impossible to build a CArray of vector2 with the API at present.

tjammer commented 3 years ago

You're right! I tried to not expose the naked ctypes structures but in doing so lost a bit of functionality. I will fix this soon.

Until then, as a workaround, you can get the ctypes typ value by creating a value of said type, taking the pointer and using Ctypes.reference_type, like so

  let vec = Vector2.create 0.0 0.0 in
  let vec_t = addr vec |> Ctypes.reference_type in

This way, it's possible to create Vector CArrays, see this example using draw_line_strip.

But it's a hack

tjammer commented 2 years ago

Hi again, I've finally updated the bindings to include the type value in every module, https://github.com/tjammer/raylib-ocaml/blob/master/src/raylib/raylib.mli#L430