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
3
votes
1 answer

What are the differences between Lwt.async and Lwt_main.run on OCaml/Node.JS?

I am experimenting with js_of_ocaml and node.js. As you know, node.js makes extensive use of callbacks to implement asynchronous requests without introducing explicit threads. In OCaml we have a very nice threading library, Lwt, coming with a very…
Michaël Le Barbier
  • 6,103
  • 5
  • 28
  • 57
3
votes
1 answer

How to use properly compile OCaml programs with js_of_ocaml?

I want to translate the following Javascript example program in OCaml, using js_of_ocaml: var AWS = require('aws-sdk'); AWS.config.region = 'us-west-2'; var s3 = new AWS.S3(); s3.listBuckets(function(err, data) { if (err) { console.log("Error:",…
Michaël Le Barbier
  • 6,103
  • 5
  • 28
  • 57
3
votes
1 answer

js_of_ocaml and event_listener

I have a div in js_of_ocaml which I want to assign an onmouseover event, like deck_div##onmouseover <- (fun () -> (* do stuff *) ) However, the function type expected is (Dom_html.divElement Js.t, Dom_html.mouseEvent Js.t)…
Olle Härstedt
  • 3,799
  • 1
  • 24
  • 57
3
votes
1 answer

Code completion not working with OcaIde + js_of_ocaml

I'm trying to use the OcaIde plugin for Eclipse with js_of_ocaml. Unfortunately the '##' syntax that js_of_ocaml uses for calling n-ary methods is upsetting the code completion. I added the following comment to the top of the code to attempt to get…
Oenotria
  • 1,692
  • 11
  • 24
2
votes
1 answer

OCaml as a compilation target

I am implementing a ISO/IEC 13211-1:1995 compliant Prolog system in OCaml. For the code generation (a.k.a. JIT) part I ... ... generate actual ".ml" code, ... ... compile it with ocamlopt, ... ... and use dynamic linking. The approach is somewhat…
repeat
  • 18,496
  • 4
  • 54
  • 166
2
votes
1 answer

How does one use dune to create a js_of_ocaml library?

I'm wondering what a dune file looks like for a library (rather than an executable) which compiles to js_of_ocaml and why is it recommended to use an executable instead?
et4te
  • 233
  • 3
  • 11
2
votes
1 answer

Unimplemented Javascript primitive caml_pure_js_expr

I want to write and compile cubes.ml such that 1) it wraps an OCaml function to make a JS function that can be called in web; 2) the OCaml function and the bytecode can still be tested in a command line under Linux. cubes.ml is as follows: let () = …
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
2
votes
1 answer

Pretty-print in js-of-ocaml

I have the following OCaml program open Js let lex s = Compiler.Parse_js.lexer_from_file s let parse s = lex s |> Compiler.Parse_js.parse let buffer_pp program = let buf = Buffer.create 10 in let pp = Compiler.Pretty_print.to_buffer buf…
objmagic
  • 1,028
  • 1
  • 9
  • 18
2
votes
2 answers

Js_of_ocaml : missing primitive when calling ocurl and str

I'm using the packages curl in order to make Http request (and the package str to use regex). I'm compiling the files in my project, no probleme and when I compile the file.byte with js_of_ocaml, I have these errors : js_of_ocaml --disable genprim…
alifirat
  • 2,899
  • 1
  • 17
  • 33
2
votes
1 answer

Js.js_array from Javascript; coerce, get/set

I have an array of objects in my Javascript file that I need to access from js_of_ocaml. I've come up with this so far: let table_decks = (Js.Unsafe.variable "table_decks" :> < deck_nr : int > Js.js_array Js.t) In Javascript, the array will be…
Olle Härstedt
  • 3,799
  • 1
  • 24
  • 57
2
votes
1 answer

Code completion not working for js_of_ocaml in typerex

Is it possible to enable type completion in Typerex for external modules? In particular I am trying to use js_of_ocaml. I can see local identifiers in code completion, so it is definitely enabled, but when I type (for example) Dom_html. I don't get…
Oenotria
  • 1,692
  • 11
  • 24
1
vote
1 answer

Check if a field exists in an object in js_of_ocaml

In my wrap.ml, I have a function as follows: Js.Unsafe.global##.test := Js.wrap_callback ( fun params -> print_endline "params##.a:"; print_endline (Js.to_string params##.a); print_endline "params##.b:"; print_endline…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
1
vote
1 answer

js_of_ocaml calling a function in ocaml from js

I have a function that uses a mutable variable that takes strings and returns strings. (its a read eval print loop interpreter) I tried exporting it as such: let () = Js.export_all (object%js method js_run_repl = Js.wrap_callback…
iluvAS
  • 513
  • 4
  • 9
1
vote
1 answer

How do I write console.log in js_of_ocaml?

How do I write console.log in js_of_ocaml? print_endline might go to the console, but I want access to trace, error, etc. Can I just define console as an external object? This does not work for me: let console = Js.Unsafe.global##console Fails…
Olle Härstedt
  • 3,799
  • 1
  • 24
  • 57
1
vote
1 answer

(js_of_ocaml) how to solve "Error: Unbound module Js"?

I want to re-compile a set of files to generate a .js file in my Mac. It used to work (long time ago), I don't know why it does not work anymore. It returned: $ make analyzejs ocamlfind ocamlc -g unix.cma -package js_of_ocaml.ppx -I…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292