tjammer/raylib-ocaml

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

Closed this issue · 2 comments

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.

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

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