Skip to content

Commit 9a41e7f

Browse files
committed
Update with gh-2150
1 parent 95036b1 commit 9a41e7f

39 files changed

+127076
-194568
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
<!DOCTYPE html>
2-
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>index (js_of_ocaml-lwt.index)</title><meta charset="utf-8"/><link rel="stylesheet" href="../odoc.support/odoc.css"/><meta name="generator" content="odoc 3.1.0"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../odoc.support/highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body class="odoc"><nav class="odoc-nav"><a href="../index.html">Up</a><a href="../index.html">Index</a> &#x00BB; js_of_ocaml-lwt</nav><header class="odoc-preamble"><h1 id="js_of_ocaml-lwt-index"><a href="#js_of_ocaml-lwt-index" class="anchor"></a>js_of_ocaml-lwt index</h1></header><div class="odoc-tocs"><nav class="odoc-toc odoc-local-toc"><ul><li><a href="#library-js_of_ocaml-lwt">Library js_of_ocaml-lwt</a></li><li><a href="#library-js_of_ocaml-lwt.graphics">Library js_of_ocaml-lwt.graphics</a></li><li><a href="#library-js_of_ocaml-lwt.logger">Library js_of_ocaml-lwt.logger</a></li></ul></nav></div><div class="odoc-content"><h2 id="library-js_of_ocaml-lwt"><a href="#library-js_of_ocaml-lwt" class="anchor"></a>Library js_of_ocaml-lwt</h2><p>The entry point of this library is the module: <a href="Js_of_ocaml_lwt/index.html"><code>Js_of_ocaml_lwt</code></a>.</p><h2 id="library-js_of_ocaml-lwt.graphics"><a href="#library-js_of_ocaml-lwt.graphics" class="anchor"></a>Library js_of_ocaml-lwt.graphics</h2><p>The entry point of this library is the module: <a href="Graphics_js/index.html"><code>Graphics_js</code></a>.</p><h2 id="library-js_of_ocaml-lwt.logger"><a href="#library-js_of_ocaml-lwt.logger" class="anchor"></a>Library js_of_ocaml-lwt.logger</h2><p>The entry point of this library is the module: <a href="Lwt_log_js/index.html"><code>Lwt_log_js</code></a>.</p></div></body></html>
2+
<html xmlns="http://www.w3.org/1999/xhtml"><head><title>index (js_of_ocaml-lwt.index)</title><meta charset="utf-8"/><link rel="stylesheet" href="../odoc.support/odoc.css"/><meta name="generator" content="odoc 3.1.0"/><meta name="viewport" content="width=device-width,initial-scale=1.0"/><script src="../odoc.support/highlight.pack.js"></script><script>hljs.initHighlightingOnLoad();</script></head><body class="odoc"><nav class="odoc-nav"><a href="../index.html">Up</a><a href="../index.html">Index</a> &#x00BB; js_of_ocaml-lwt</nav><header class="odoc-preamble"><h1 id="js_of_ocaml-lwt-index"><a href="#js_of_ocaml-lwt-index" class="anchor"></a>js_of_ocaml-lwt index</h1></header><div class="odoc-tocs"><nav class="odoc-toc odoc-local-toc"><ul><li><a href="#library-js_of_ocaml-lwt">Library js_of_ocaml-lwt</a></li><li><a href="#library-js_of_ocaml-lwt.graphics">Library js_of_ocaml-lwt.graphics</a></li></ul></nav></div><div class="odoc-content"><h2 id="library-js_of_ocaml-lwt"><a href="#library-js_of_ocaml-lwt" class="anchor"></a>Library js_of_ocaml-lwt</h2><p>The entry point of this library is the module: <a href="Js_of_ocaml_lwt/index.html"><code>Js_of_ocaml_lwt</code></a>.</p><h2 id="library-js_of_ocaml-lwt.graphics"><a href="#library-js_of_ocaml-lwt.graphics" class="anchor"></a>Library js_of_ocaml-lwt.graphics</h2><p>The entry point of this library is the module: <a href="Graphics_js/index.html"><code>Graphics_js</code></a>.</p></div></body></html>

doc/dev/manual/bindings.wiki

Lines changed: 2 additions & 205 deletions
Original file line numberDiff line numberDiff line change
@@ -1,206 +1,3 @@
1-
= How to bind a JS library for OCaml
1+
= Binding a JS library
22

3-
== Accessing a JS variable, ex: {{{document}}}:
4-
Write in .ml:
5-
6-
<<code language="ocaml"|
7-
let v = (Js.Unsafe.js_expr "window")##.document
8-
>>
9-
Alternatively, the global object can be used. In the browser, it refers to {{{window}}}.
10-
<<code language="ocaml"|
11-
let v = Js.Unsafe.global##.document
12-
>>
13-
14-
and in .mli:
15-
16-
<<code language="ocaml"|
17-
val v : ... Js.t
18-
>>
19-
20-
Be careful the function <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsafe.js_expr>>
21-
and the value <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsafe.global>> are not typed.
22-
Verify the library documentation before writing the type.
23-
24-
== Binding a JS function
25-
26-
Example from the Js module:
27-
<<code language="ocaml"|
28-
let decodeURI (s : js_string t) : js_string t =
29-
Js.Unsafe.fun_call (Js.Unsafe.js_expr "decodeURI") [|Js.Unsafe.inject s|]
30-
>>
31-
32-
Have a look at the <<a_api subproject="js_of_ocaml"|module Js_of_ocaml.Js.Unsafe>> module API.
33-
34-
== Using a JS constructor, ex: {{{F}}}:
35-
Write in .ml:
36-
37-
<<code language="ocaml"|
38-
let f = Js.Unsafe.global##._F
39-
>>
40-
and in .mli:
41-
42-
<<code language="ocaml"|
43-
val f : (... -> ... Js.t) Js.constr
44-
>>
45-
46-
and if you want to use JS overloading, do, for example:
47-
<<code language="ocaml"|
48-
val f_fromInt : (int -> ... Js.t) Js.constr
49-
val f_fromString : (js_string t -> ... Js.t) Js.constr
50-
val f_blah : (#Dom_html.element t -> js_string t -> ... Js.t) Js.constr
51-
>>
52-
53-
== Accessing or modifying a JS property to an element
54-
55-
When a property is missing in the OCaml interface of an element (for example
56-
it has been dynamically added by a library), you can access using unsafe
57-
features:
58-
59-
<<code language="ocaml"|
60-
(Js.Unsafe.coerce elt)##.blah
61-
>>
62-
63-
If you want to add yourself a new property:
64-
<<code language="ocaml"|
65-
(Js.Unsafe.coerce elt)##.blah := v
66-
>>
67-
68-
Here, {{{v}}} may be a JS value or an OCaml value.
69-
70-
If you want to do that in type safe manner, just define new types for the
71-
extended elements, or wrap the unsafe functions inside a getter and setter.
72-
73-
== Binding a JS object
74-
75-
Write in .ml and in .mli:
76-
77-
<<code language="ocaml"|
78-
class type my_js_type = object
79-
80-
(* read only property, read value with t##.prop1 *)
81-
method prop1 : int readonly_prop
82-
83-
(* write only property, write value with t##.prop2 := float 3.14 *)
84-
method prop2 : number t writeonly_prop
85-
86-
(* both read and write *)
87-
method prop3 : int prop
88-
89-
(* method or property starting with a capital letter can be prepend
90-
with an underscore. *)
91-
method _Array : ... (* to access the JavaScript property or method Array *)
92-
93-
(* Define two methods with different types, that translate to
94-
the same JavaScript method. *)
95-
method my_fun_int : int -> unit meth
96-
method my_fun_string : js_string t -> unit meth
97-
(* Both will actually call the my_fun JavaScript method. *)
98-
99-
(* To call a javascript method starting with one underscore *)
100-
method __hiddenfun : ..
101-
method __hiddenfun_ : ..
102-
method __hiddenfun_something : ..
103-
(* This will call the _hiddenfun Javascript method *)
104-
105-
(* To call the javascript method '_' *)
106-
method __ : ..
107-
end
108-
>>
109-
110-
=== Example binding some constants:
111-
112-
For example if the JS class is used to define three constants {{{thelib.Theclass.VALUEA}}}, {{{thelib.Theclass.VALUEB}}}, {{{thelib.Theclass.VALUEC}}},
113-
114-
Since OCaml doesn't allow method names to start with capitalized letters, we can add an {{{_}}}
115-
116-
write in .ml and .mli:
117-
118-
<<code language="ocaml"|
119-
type thetype
120-
121-
class type theclass = object
122-
method _VALUEA : thetype readonly_prop
123-
method _VALUEB : thetype readonly_prop
124-
method _VALUEC : thetype readonly_prop
125-
end
126-
>>
127-
128-
and in .ml:
129-
130-
<<code language="ocaml"|
131-
let theclass = (Js.Unsafe.js_expr "thelib")##._Theclass
132-
>>
133-
134-
and in .mli:
135-
136-
<<code language="ocaml"|
137-
val theclass : theclass t
138-
>>
139-
140-
== Constructing JS objects manually
141-
If you want to construct a JS object manually
142-
(without calling a function or a constructor), you can use
143-
the <<a_manual chapter="Ppx"|Ppx>> syntax extension.
144-
145-
For example:
146-
<<code language="ocaml"|
147-
let options = object%js
148-
val x = 3 (* read-only prop *)
149-
val mutable y = 4 (* read/write prop *)
150-
end
151-
>>
152-
153-
You can also use the unsafe <<a_api subproject="js_of_ocaml"|val Js_of_ocaml.Js.Unsafe.obj>>.
154-
155-
== Set/get variables
156-
157-
You can access every variable through the global javascript object ({{{window}}}):
158-
159-
If the variable {{{var}}} has type {{{t Js.t}}}
160-
161-
<<code language="ocaml"|
162-
let set (x:t Js.t) = Js.Unsafe.global##.var := x
163-
let get x : t Js.t = Js.Unsafe.global##.var
164-
>>
165-
166-
== Object property with multiple types
167-
168-
If you want to read a property of an object which can have multiple types, you can define an intermediate type to do typesafe casting ex:
169-
170-
Suppose the object {{{obj}}} has a property {{{prop}}} which can be either a string or a Dom node:
171-
172-
<<code language="ocaml"|
173-
174-
type dom_or_string
175-
176-
class type obj = object
177-
method prop : dom_or_string Js.t prop
178-
end
179-
180-
let obj : obj Js.t = Js.Unsafe.js_expr "obj"
181-
182-
let string_constr : Js.js_string Js.t Js.constr = Js.Unsafe.global##._String
183-
184-
let cast_string (x:dom_or_string Js.t) : Js.js_string Js.t Js.opt =
185-
if Js.instanceof x string_constr
186-
then Js.some (Js.Unsafe.coerce x)
187-
else Js.null
188-
189-
let node_constr : Dom.node Js.t Js.constr = Js.Unsafe.global##._Node
190-
191-
let cast_node (x:dom_or_string Js.t) : Dom.node Js.t Js.opt =
192-
if Js.instanceof x node_constr
193-
then Js.some (Js.Unsafe.coerce x)
194-
else Js.null
195-
196-
>>
197-
198-
== Check availability of method
199-
200-
It is frequent that some methods are not implemented in some browsers.
201-
202-
To check the presence of method {{{met}}}:
203-
204-
<<code language="ocaml"|
205-
let check_met obj = Js.Optdef.test ((Js.Unsafe.coerce obj)##.met)
206-
>>
3+
This page has been merged into <<a_manual chapter="javascript-interop"|JavaScript interop>>.

doc/dev/manual/build-toplevel.wiki

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,40 @@
1-
= How to build a toplevel =
1+
= Building a toplevel
22

3-
First, initialize the toplevel using {{{Js_of_ocaml_toplevel.JsooTop.initialize}}}.
3+
First, initialize the toplevel using <<a_api subproject="js_of_ocaml-toplevel"|val Js_of_ocaml_toplevel.JsooTop.initialize>>.
44

5-
Then, build your bytecode program with debug enabled (**-g**) and linkall (**-linkall**). You should obviously link in all the libraries you want accessible in the final toplevel.
5+
Then, build your bytecode program with debug enabled ({{{-g}}}) and linkall ({{{-linkall}}}). Link in all the libraries you want accessible in the final toplevel.
66

7-
Finally, compile your toplevel to JavaScript passing the {{{--toplevel}}} flags to the js_of_ocaml compiler.
7+
Finally, compile your toplevel to JavaScript passing the {{{--toplevel}}} flag to the js_of_ocaml compiler.
88

99
If you want to limit the set of modules available in the toplevel, you can explicitly pass a list of compilation units that should be accessible using the {{{--export FILE}}} flag.
10-
**FILE** must contain names of compilation unit to export - one per line. The **jsoo_listunits** tool, provided by the **js_of_ocaml-toplevel** opam package, can be used to generate this list
11-
from a set of findlib libraries.
10+
{{{FILE}}} must contain names of compilation units to export, one per line. The {{{jsoo_listunits}}} tool, provided by the {{{js_of_ocaml-toplevel}}} opam package, can be used to generate this list from a set of findlib libraries.
1211

13-
For example, the following command will create a file **FILE** containing all compilation unit names provided by the findlib libraries **stdlib** and **str**.
12+
For example, the following command will create a file containing all compilation unit names provided by the findlib libraries {{{stdlib}}} and {{{str}}}:
1413
{{{
15-
jsoo_listunits -o FILE stdlib str
14+
jsoo_listunits -o units.txt stdlib str
1615
}}}
1716

17+
= Using the Dynlink library
1818

19-
Note that toplevels currently cannot be built using separate compilation.
19+
OCaml supports dynlink of bytecode files using the {{{dynlink}}} library. To use it when compiled to JavaScript:
2020

21+
# Link {{{js_of_ocaml-compiler.dynlink}}} to initialize dynlink support (initialization is automatic via side-effect)
22+
# Build your bytecode program with debug enabled ({{{-g}}}) and linkall ({{{-linkall}}})
23+
# Compile your program to JavaScript passing the {{{--dynlink}}} flag
2124
22-
= How to build a program using the **Dynlink** library =
25+
==@@id="example"@@ Example
2326

24-
OCaml supports dynlink of bytecode files using the **dynlink** library. In order to work when compiled to JavaScript, one needs to follow the following steps:
25-
26-
First, make sure to link **js_of_ocaml-compiler.dynlink** to initialize the support for dynlink (the initialization is done automatically by side-effect).
27-
28-
Then, build your bytecode program with debug enabled (**-g**) and linkall (**-linkall**).
29-
30-
Finally, compile your program to JavaScript passing the {{{--dynlink}}} flags to the js_of_ocaml compiler.
31-
32-
Here is an example showing how to compile and use a program using Dynlink:
3327
{{{
34-
# cat main.ml
35-
let () = Dynlink.loadfile "./plugin.cmo"
28+
# main.ml
29+
let () = Dynlink.loadfile "./plugin.cmo"
3630

37-
# Compiling main program
38-
ocamlfind ocamlc -linkpkg -package dynlink -package js_of_ocaml-compiler.dynlink main.ml -o main.bc
39-
js_of_ocaml main.bc --dynlink
31+
# Compiling main program
32+
ocamlfind ocamlc -linkpkg -package dynlink -package js_of_ocaml-compiler.dynlink main.ml -o main.bc
33+
js_of_ocaml main.bc --dynlink
4034

41-
# Compiling plugin
42-
ocamlfind ocamlc -c plugin.ml
35+
# Compiling plugin
36+
ocamlfind ocamlc -c plugin.ml
4337

44-
# Test
45-
node ./main.js
38+
# Test
39+
node ./main.js
4640
}}}

doc/dev/manual/camlp4.wiki

Lines changed: 3 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,5 @@
1-
= Camlp4 syntax extension for Js_of_ocaml
1+
= Camlp4 syntax extension
22

3-
WARNING: The Camlp4 syntax extension is no longer part of the js_of_ocaml distribution.
3+
The Camlp4 syntax extension is deprecated and no longer part of js_of_ocaml.
44

5-
A Camlp4 syntax extension is available for manipulating object properties,
6-
invoking methods and creating objects.
7-
We advise to use the <<a_manual chapter="ppx" |Ppx>> syntax extension instead.
8-
9-
The syntax and typing rules are as follows:
10-
11-
* Getting a property
12-
{{{
13-
obj : <m : u prop> Js.t
14-
-----------------------
15-
obj##m : u
16-
}}}
17-
18-
* Setting a property
19-
{{{
20-
obj : <m : u prop> Js.t
21-
e : u
22-
-----------------------
23-
obj##m <- e : unit
24-
}}}
25-
26-
* Invoking a method
27-
{{{
28-
obj : <m : t_1 -> ... -> t_n -> u meth; ..> Js.t
29-
e_i : t_i (1 <= i <= n)
30-
-------------------------------------------------
31-
obj##m(e_1, ..., e_n) : u
32-
}}}
33-
34-
* Using an object constructor
35-
{{{
36-
constr : (t_1 -> ... -> t_n -> u Js.t) Js.constr
37-
e_i : t_i (1 <= i <= n)
38-
------------------------------------------------
39-
jsnew constr (e1, ..., en) : u Js.t
40-
}}}
41-
42-
* Creating a literal object
43-
<<code language="ocaml"|
44-
jsobject (self) (* Equivalent of this *)
45-
val x = 3 (* read-only prop *)
46-
val mutable y = 4 (* read/write prop *)
47-
method foo i = self##y <- self##x + i
48-
end
49-
>>
50-
Properties are defined with the [val] keyword. [mutable] makes the
51-
property writable. [self] can be any identifier and will be bind
52-
to [this] in javascript.
53-
54-
In this case, the object has the following type:
55-
<<code language="ocaml"|
56-
< foo : int -> unit Js.meth;
57-
x : int Js.readonly_prop;
58-
y : int Js.prop
59-
> Js.t
60-
>>
5+
Use the <<a_manual chapter="ppx"|PPX syntax extension>> instead.

0 commit comments

Comments
 (0)