Questions tagged [js-of-ocaml]

Js_of_ocaml is a compiler from OCaml bytecode to JavaScript, making it possible to run OCaml programs in a web browser.

Features

  • The whole language and most of the standard library are supported.
  • The compiler is easy to install: it only depends on Findlib and optionally .
  • The generated code is independent of Eliom and the Ocsigen server. You can use it with any web server.
  • You can use a standard installation of OCaml to compile your programs. In particular, you do not have to recompile a library to use it with Js_of_ocaml. You just have to link your program with a specific library to interface with browser APIs.

Useful resources

66 questions
8
votes
1 answer

How to invoke a function generated by js_of_ocaml?

I am new to JavaScript, I am trying to use js_of_ocaml. I first wrote a very simple cubes.ml: let simple (a: int) = a + 1234 Then complied it: ocamlfind ocamlc -package js_of_ocaml -package js_of_ocaml.syntax \ -syntax camlp4o -linkpkg…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
7
votes
3 answers

How to use modules with js_of_ocaml?

I am currently working on a website project written in OCaml and compiled to javascript using js_of_ocaml. It works pretty well as long as I have only one source file using the command ocamlfind ocamlc -package js_of_ocaml -package…
Thomash
  • 6,339
  • 1
  • 30
  • 50
7
votes
1 answer

Marshal and magic_copy in js_of_ocaml

Newbie question. I'm going through the very nice Ocaml ORA book. When I went to play with the magic_copy example from the section on Marshal, I was closer to a browser than a terminal, so I tried it out in ocsigen's toplevel in a browser, where I…
ImAlsoGreg
  • 655
  • 6
  • 17
6
votes
3 answers

js_of_ocaml and Core

I'm quite new to OCaml and to the js_of_ocaml compiler in particular. Did someone manage to compile the application which uses Jane Street Core with js_of_ocaml? I get lots of "missing primitives" warnings during the compilation, and then when I try…
George Karpenkov
  • 2,094
  • 1
  • 16
  • 36
6
votes
1 answer

js_of_ocaml and Deriving_Json

I need some help to get js_of_ocaml working. There's not much information about it on the net, and the manual is very sparse (no snippets or usage examples, no comment sections). I have a Card module on the server with a card record. I'm sending a…
Olle Härstedt
  • 3,799
  • 1
  • 24
  • 57
5
votes
1 answer

How to produce a `ArrayBuffer` from `bytes` using `js_of_ocaml`

I am building a JavaScript library that is implemented in Ocaml and compiled to JavaScript using js_of_ocaml. One of my Ocaml function returns a string with binary data. How can I expose that using js_of_ocaml as a ArrayBuffer?
Joachim Breitner
  • 25,395
  • 6
  • 78
  • 139
5
votes
2 answers

How to compile a simple Command-line OCaml script into Javascript

I have a simple command line OCaml application that performs a computation on Sys.argv.(1) and outputs the result to stdout. I can compile it to Javascript with js_of_ocaml, but it gives me a lot of errors about caml_ml_output_char being undefined.…
gmatht
  • 835
  • 6
  • 14
5
votes
1 answer

A canvas with a horizontal scroll bar in js_of_ocaml

I create a canvas in js_of_ocaml as below. (* create document *) let document = Dom_html.window##document (* function to create canvas *) let create_canvas () = let canvas = Dom_html.createCanvas document in canvas##width <- 500; canvas##height…
mmsss
  • 263
  • 1
  • 2
  • 7
5
votes
1 answer

Linking a library via ocamlbuild/ocamlfind

I have a locally pinned OPAM project called ojasmine which I want to compile as a library to be used by another project called test_tournabox (ultimately compiling to javascript). However, the compilation of test_tournabox is failing with a link…
Lyn Headley
  • 11,368
  • 3
  • 33
  • 35
5
votes
1 answer

Communication client-server with OCaml marshalled data

I want to do a client-side js_of_ocaml application with a server in OCaml, with contraints described below, and I would like to know if the approach below is right or if there is a more efficient one. The server can sometimes send large quantities…
user3894928
4
votes
1 answer

Make compatible ocaml, camlp4, ppx, node, js_of_ocaml, ocamlbuild

After installing npm and node, compiling OCaml files with js_of_ocaml gave errors, thus I did opam switch reinstall system: :testweb $ opam switch reinstall system Your system compiler has been changed. Do you want to upgrade your OPAM installation…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
4
votes
3 answers

Equivalent of document.getElementsByClassName

I can't find a js_of_ocaml equivalent of document.getElementsByClassName. What is the canonical way to do? EDIT : I'm using js_of_ocaml v2.5.
Antoine
  • 1,782
  • 1
  • 14
  • 32
4
votes
1 answer

How can I add a onclick method using js_of_ocaml?

Hi suppose I have a button with id form-submit and I have the following function in my OCaml file: let () = let form_submit = Dom_html.getElementById "form-submit" in ... What is the right way to add a on_click method to the button? Should I…
Bob Fang
  • 6,963
  • 10
  • 39
  • 72
4
votes
2 answers

How can I map OCaml bytecode to its original source code location?

Is there some nice feature of the format or library for going from some part of the bytecode to the line of code it originally came from? This would obviously be useful for debugging and error messages. In particular, I'm looking at how hard it…
Tikhon Jelvis
  • 67,485
  • 18
  • 177
  • 214
3
votes
1 answer

What does "##" after variable mean?

Js.coerce_opt (Dom_html.document##getElementById id) I'm new to OCaml, and I'm dealing with Js_of_Ocaml recently. I've seen code as above that includes two pounds after between variable and function. What do they mean?
Dier Hou
  • 33
  • 4
1
2 3 4 5