Source file sys_js.ml
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
open! Import
external create_file : name:string -> content:string -> unit = "caml_create_file"
external read_file : name:string -> string = "caml_read_file_content"
let update_file ~name ~content =
let oc = open_out name in
output_string oc content;
close_out oc
external set_channel_output' :
out_channel -> (Js.js_string Js.t -> unit) Js.callback -> unit
= "caml_ml_set_channel_output"
external set_channel_input' : in_channel -> (unit -> string) Js.callback -> unit
= "caml_ml_set_channel_refill"
let set_channel_flusher (out_channel : out_channel) (f : string -> unit) =
let f' : (Js.js_string Js.t -> unit) Js.callback =
Js.wrap_callback (fun s -> f (Js.to_bytestring s))
in
set_channel_output' out_channel f'
let set_channel_filler (in_channel : in_channel) (f : unit -> string) =
let f' : (unit -> string) Js.callback = Js.wrap_callback f in
set_channel_input' in_channel f'
external mount_point : unit -> string list = "caml_list_mount_point"
external mount_autoload :
string -> (string -> string -> string option) Js.callback -> unit
= "caml_mount_autoload"
external unmount : string -> unit = "caml_unmount"
let mount ~path f =
mount_autoload path (Js.wrap_callback (fun prefix path -> f ~prefix ~path))
let unmount ~path = unmount path
let js_of_ocaml_version =
if String.equal Lib_version.git_version ""
then Lib_version.s
else Lib_version.s ^ "+" ^ Lib_version.git_version