-
-
Save mooreryan/b9c9236343d2e1b567941f629a213ee7 to your computer and use it in GitHub Desktop.
Export OCaml to JavaScript
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(executable | |
(name hello) | |
(libraries js_of_ocaml) | |
(modes js) | |
(preprocess | |
(pps js_of_ocaml-ppx))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ node test.js | |
11.5 | |
3.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Js_of_ocaml | |
let add1 x = x +. 1.0 | |
let () = Js.export "add1" add1 | |
let () = | |
Js.export "lib" | |
(object%js | |
method add x y = x +. y | |
end) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Assuming you run this from the dune-project root. | |
const hello = require("./_build/default/hello.bc"); | |
console.log(hello.add1(10.5)); | |
console.log(hello.lib.add(1, 2.5)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment