Skip to content

Commit 97e0a60

Browse files
committed
Add raylib-callbacks package
1 parent f17235c commit 97e0a60

File tree

9 files changed

+154
-50
lines changed

9 files changed

+154
-50
lines changed

dune-project

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
(description "OCaml bindings for raylib")
1818
(synopsis "OCaml bindings for raylib")
1919
(depends
20+
(ocaml (>= 4.08.0))
2021
(dune (>= 3.17))
2122
dune-configurator
2223
(ctypes (>= 0.14))
@@ -36,13 +37,27 @@
3637
(raylib (>= 1.4.0))
3738
(patch (>= 3.0.0))))
3839

40+
(package
41+
(name raylib-callbacks)
42+
(version 1.4.0)
43+
(description "OCaml bindings for raygui")
44+
(synopsis "OCaml bindings for raygui")
45+
(depends
46+
(ocaml (>= 4.05))
47+
(dune (>= 3.17))
48+
dune-configurator
49+
(ctypes (>= 0.14))
50+
(ctypes-foreign (>= 0.14))
51+
(raylib (>= 1.4.0))))
52+
3953
(package
4054
(name raylib-gen)
4155
(version 0.1.0)
4256
(description "Binding generation for raylib")
4357
(synopsis "Binding generation for raylib")
4458
(depends
45-
(dune (>= 3.17))
59+
(ocaml (>= 4.08.0))
60+
(dune (>= 3.17))
4661
yojson
4762
re
4863
containers))

src/c/raylib/functions.ml

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -245,22 +245,6 @@ module Functions (F : Ctypes.FOREIGN) = struct
245245
(* let set_trace_log_callback = *)
246246
(* foreign "SetTraceLogCallback" (trace_log_callback @-> returning void) *)
247247

248-
(* let set_load_file_data_callback = *)
249-
(* foreign "SetLoadFileDataCallback" *)
250-
(* (load_file_data_callback @-> returning void) *)
251-
252-
(* let set_save_file_data_callback = *)
253-
(* foreign "SetSaveFileDataCallback" *)
254-
(* (save_file_data_callback @-> returning void) *)
255-
256-
(* let set_load_file_text_callback = *)
257-
(* foreign "SetLoadFileTextCallback" *)
258-
(* (load_file_text_callback @-> returning void) *)
259-
260-
(* let set_save_file_text_callback = *)
261-
(* foreign "SetSaveFileTextCallback" *)
262-
(* (save_file_text_callback @-> returning void) *)
263-
264248
let _load_file_data =
265249
foreign "LoadFileData" (string @-> ptr uint @-> returning (ptr uchar))
266250

@@ -1731,20 +1715,6 @@ module Functions (F : Ctypes.FOREIGN) = struct
17311715
let set_audio_stream_buffer_size_default =
17321716
foreign "SetAudioStreamBufferSizeDefault" (int @-> returning void)
17331717

1734-
(* let set_audio_stream_callback = *)
1735-
(* foreign "SetAudioStreamCallback" (AudioStream.t @-> audio_callback @-> returning void) *)
1736-
1737-
(* let attach_audio_stream_processor = *)
1738-
(* foreign "AttachAudioStreamProcessor" (AudioStream.t @-> audio_callback @-> returning void) *)
1739-
1740-
(* let detach_audio_stream_processor = *)
1741-
(* foreign "DetachAudioStreamProcessor" (AudioStream.t @-> audio_callback @-> returning void) *)
1742-
1743-
(* let attach_audio_mixed_processor = *)
1744-
(* foreign "AttachAudioMixedProcessor" (audio_callback @-> returning void) *)
1745-
1746-
(* let detach_audio_mixed_processor = *)
1747-
(* foreign "DetachAudioMixedProcessor" (audio_callback @-> returning void) *)
17481718
(*---------------------------------------------------------------------------------- *)
17491719
(* Module Functions Definition - Utils math *)
17501720
(*---------------------------------------------------------------------------------- *)

src/c/raylib_callbacks/dune

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
(library
2+
(name raylib_callbacks_c)
3+
(package raylib-callbacks)
4+
(libraries raylib_c ctypes-foreign)
5+
(ctypes
6+
(external_library_name raylib)
7+
(build_flags_resolver
8+
(vendored
9+
(c_flags :standard "-I../vendor/raylib/src")
10+
(c_library_flags :standard)))
11+
(headers
12+
(include "raylib.h" "config.h"))
13+
(type_description
14+
(instance Types)
15+
(functor Functions))
16+
(function_description
17+
(instance Functions)
18+
(functor Functions))
19+
(generated_types Raylib_callbacks_types_generated)
20+
(generated_entry_point Raylib_callbacks_generated))
21+
(library_flags
22+
(:include ../library_flags.sexp)))
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
open Ctypes
2+
3+
module Functions (F : Ctypes.FOREIGN) = struct
4+
open F
5+
open Raylib_c.Types
6+
7+
let audio_callback =
8+
Foreign.funptr Ctypes.(ptr void @-> uint @-> returning void)
9+
10+
let set_audio_stream_callback =
11+
foreign "SetAudioStreamCallback"
12+
(AudioStream.t @-> audio_callback @-> returning void)
13+
14+
let attach_audio_stream_processor =
15+
foreign "AttachAudioStreamProcessor"
16+
(AudioStream.t @-> audio_callback @-> returning void)
17+
18+
let detach_audio_stream_processor =
19+
foreign "DetachAudioStreamProcessor"
20+
(AudioStream.t @-> audio_callback @-> returning void)
21+
22+
let attach_audio_mixed_processor =
23+
foreign "AttachAudioMixedProcessor" (audio_callback @-> returning void)
24+
25+
let detach_audio_mixed_processor =
26+
foreign "DetachAudioMixedProcessor" (audio_callback @-> returning void)
27+
28+
let load_file_data_callback =
29+
Foreign.funptr Ctypes.(string @-> ptr int @-> returning (ptr uchar))
30+
31+
let save_file_data_callback =
32+
Foreign.funptr Ctypes.(string @-> ptr void @-> int @-> returning bool)
33+
34+
let load_file_text_callback =
35+
Foreign.funptr Ctypes.(string @-> returning (ptr char))
36+
37+
let save_file_text_callback =
38+
Foreign.funptr Ctypes.(string @-> ptr char @-> returning bool)
39+
40+
let set_load_file_data_callback =
41+
foreign "SetLoadFileDataCallback"
42+
(load_file_data_callback @-> returning void)
43+
44+
let set_save_file_data_callback =
45+
foreign "SetSaveFileDataCallback"
46+
(save_file_data_callback @-> returning void)
47+
48+
let set_load_file_text_callback =
49+
foreign "SetLoadFileTextCallback"
50+
(load_file_text_callback @-> returning void)
51+
52+
let set_save_file_text_callback =
53+
foreign "SetSaveFileTextCallback"
54+
(save_file_text_callback @-> returning void)
55+
end
56+
57+
module Types (F : Ctypes.TYPE) = struct end

src/callbacks/callbacks.ml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
type audio_callback = unit Ctypes.ptr -> Unsigned.uint -> unit
2+
3+
type load_file_data_callback =
4+
string -> int Ctypes.ptr -> Unsigned.uchar Ctypes.ptr
5+
6+
type save_file_data_callback = string -> unit Ctypes.ptr -> int -> bool
7+
type load_file_text_callback = string -> char Ctypes.ptr
8+
type save_file_text_callback = string -> char Ctypes.ptr -> bool
9+
10+
include Raylib_callbacks_c.Raylib_callbacks_generated.Functions

src/callbacks/callbacks.mli

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
(** Audio callbacks*)
2+
3+
type audio_callback = unit Ctypes.ptr -> Unsigned.uint -> unit
4+
5+
val set_audio_stream_callback : Raylib.AudioStream.t -> audio_callback -> unit
6+
(** [set_audio_stream_callback stream callback] Audio thread callback to request new data*)
7+
8+
val attach_audio_stream_processor :
9+
Raylib.AudioStream.t -> audio_callback -> unit
10+
(** [attach_audio_stream_processor stream processor] Attach audio stream processor to stream, receives the samples as 'float'*)
11+
12+
val detach_audio_stream_processor :
13+
Raylib.AudioStream.t -> audio_callback -> unit
14+
(** [detach_audio_stream_processor stream processor] Detach audio stream processor from stream*)
15+
16+
val attach_audio_mixed_processor : audio_callback -> unit
17+
(** [attach_audio_mixed_processor processor] Attach audio stream processor to the entire audio pipeline, receives the samples as 'float'*)
18+
19+
val detach_audio_mixed_processor : audio_callback -> unit
20+
(** [detach_audio_mixed_processor processor] Detach audio stream processor from the entire audio pipeline*)
21+
22+
(** File callbacks *)
23+
24+
type load_file_data_callback =
25+
string -> int Ctypes.ptr -> Unsigned.uchar Ctypes.ptr
26+
27+
type save_file_data_callback = string -> unit Ctypes.ptr -> int -> bool
28+
type load_file_text_callback = string -> char Ctypes.ptr
29+
type save_file_text_callback = string -> char Ctypes.ptr -> bool
30+
31+
val set_load_file_data_callback : load_file_data_callback -> unit
32+
(** [set_load_file_data_callback callback] Set custom file binary data loader*)
33+
34+
val set_save_file_data_callback : save_file_data_callback -> unit
35+
(** [set_save_file_data_callback callback] Set custom file binary data saver*)
36+
37+
val set_load_file_text_callback : load_file_text_callback -> unit
38+
(** [set_load_file_text_callback callback] Set custom file text data loader*)
39+
40+
val set_save_file_text_callback : save_file_text_callback -> unit
41+
(** [set_save_file_text_callback callback] Set custom file text data saver*)

src/callbacks/dune

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
(library
2+
(name callbacks)
3+
(public_name raylib-callbacks)
4+
(libraries raylib raylib_callbacks_c))

src/raylib/raylib.mli

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,7 +1226,7 @@ module Wave : sig
12261226
end
12271227

12281228
module AudioStream : sig
1229-
type t'
1229+
type t' = Raylib_c.Types.AudioStream.t
12301230
type t = t' ctyp
12311231

12321232
val t : t Ctypes.typ
@@ -3250,19 +3250,4 @@ val set_audio_stream_pan : AudioStream.t -> float -> unit
32503250
val set_audio_stream_buffer_size_default : int -> unit
32513251
(** [set_audio_stream_buffer_size_default size] Default size for new audio streams*)
32523252

3253-
(* val set_audio_stream_callback : AudioStream.t -> audio_callback -> unit *)
3254-
(* (\** [set_audio_stream_callback stream callback] Audio thread callback to request new data*\) *)
3255-
3256-
(* val attach_audio_stream_processor : AudioStream.t -> audio_callback -> unit *)
3257-
(* (\** [attach_audio_stream_processor stream processor] Attach audio stream processor to stream, receives the samples as 'float'*\) *)
3258-
3259-
(* val detach_audio_stream_processor : AudioStream.t -> audio_callback -> unit *)
3260-
(* (\** [detach_audio_stream_processor stream processor] Detach audio stream processor from stream*\) *)
3261-
3262-
(* val attach_audio_mixed_processor : audio_callback -> unit *)
3263-
(* (\** [attach_audio_mixed_processor processor] Attach audio stream processor to the entire audio pipeline, receives the samples as 'float'*\) *)
3264-
3265-
(* val detach_audio_mixed_processor : audio_callback -> unit *)
3266-
(* (\** [detach_audio_mixed_processor processor] Detach audio stream processor from the entire audio pipeline*\) *)
3267-
32683253
module Rlgl = Rlgl

src/util/raylib_gen.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ let () =
567567
^ (enums |> List.map Enum.itf |> String.concat "")
568568
^ "val max_material_maps : int\n\n" ^ "val max_shader_locations : int\n\n"
569569
in
570-
print_string itf;
570+
(* print_string itf; *)
571571
ignore itf;
572572

573573
let itf = types |> List.map Type.itf |> String.concat "" in
@@ -584,6 +584,6 @@ let () =
584584
(* print_string stubs; *)
585585
ignore stubs;
586586
let itf = funcs |> List.map Function.itf |> String.concat "\n" in
587-
(* print_string itf; *)
588-
ignore itf;
587+
print_string itf;
588+
(* ignore itf; *)
589589
()

0 commit comments

Comments
 (0)