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
1
vote
0 answers

How could JavaScript catch exceptions raised by OCaml?

I have a OCaml projet, which is later converted to JavaScript by js_of_ocaml. I wrap some functions like follows: Js.Unsafe.global##.parseFile := Js.wrap_callback (fun s -> Js.string (E.parse_file (Js.to_string s))); Then, in JavaScript, I…
SoftTimur
  • 5,630
  • 38
  • 140
  • 292
1
vote
1 answer

Get children of Dom_html.element

In js_of_ocaml, is it possible to get the child nodes of Dom_html.element? I know that the class inherits Dom.node, and thus has the childNodes method. But since it is a method from Dom.node, it returns values of Dom.node types. And I need those…
Shaac
  • 195
  • 14
1
vote
1 answer

How to capture stdout of js_of_ocaml toplevel

I have this js_of_ocaml code that takes a string and executes it (assuming the string is OCaml code): let () = JsooTop.initialize () let execute code = let code = Js.to_string code in let buffer = Buffer.create 100 in let formatter =…
Flux
  • 9,805
  • 5
  • 46
  • 92
1
vote
1 answer

Making a node module with js_of_ocaml

The js_of_ocaml documentation says about making a Node.js module: Js.export and Js.export_all will export a value to module.exports if it exists. What I'm confused about is the "if it exists" part. How do I make sure that the module def exists?…
jmite
  • 8,171
  • 6
  • 40
  • 81
1
vote
1 answer

Unit Tests in the Eliom Framework

I am building a new project using Eliom and having trouble setting up a compilation process for unit tests using OUnit. I have two files: Js_Client_Code.eliom - contains all of the client side code Project.eliom - contains all of the server side…
Thomas
  • 347
  • 3
  • 19
1
vote
1 answer

Calling an external Js lib from Eliom client code

I am trying Eliom right now, to see what I can do with it. I want to call an external javascript library from my eliom client code. The example code I'm trying is the following: [%%client let three_lib = Js.Unsafe.js_expr "THREE" in let scene2…
1
vote
2 answers

js_of_ocaml.ppx not being find

I'm trying to run js_of_eliom, but it seems that it don't have ppx_deriving This is the message i got when i do a make: js_of_eliom -ppx -c -package lwt -package js_of_ocaml.deriving -package js_of_ocaml.ppx simple_pomodoro.eliom Fatal error:…
João Zeni
  • 21
  • 1
  • 3
1
vote
1 answer

Tyxml - adding svg element to dom tree

Just beginning to break the ice with Tyxml - can't seem to get any further than this - let main _ = let d = Dom_html.window ## document in let c = Dom_html.createCanvas d in let s = Dom_svg.createCircle c in c ## width <- Js.string "100"; …
njb
  • 93
  • 8
1
vote
1 answer

binding library : returning untyped object - method definition

Part of a library I'm trying to bind returns an object - Editor.prototype.getHandlers = function() { return { 'shape.append': require('./draw/AppendShapeHandler'), 'shape.create': require('./draw/CreateShapeHandler') }; }; What I can't…
njb
  • 93
  • 8
1
vote
1 answer

Inserting Tyxml_js.Svg values in js_of_ocaml's Dom_svg

Let's say I create an SVG rect, using Tyxml's syntax: let rect_elt = <:svg< >> How can I insert it inside the DOM using the API of js_of_ocaml ? I want to do something like that: let _ = let rect_elt = <:svg< >> in …
Antoine
  • 1,782
  • 1
  • 14
  • 32
1
vote
1 answer

Meaning of # character in front of js_of_ocaml dom types

What is the meaning of the '#' in the following signature? val insertBefore : #node Js.t -> #node Js.t -> #node Js.t Js.opt -> unit
Antoine
  • 1,782
  • 1
  • 14
  • 32
1
vote
1 answer

Compiling ocaml can't find module in opam library, Js.ml in js_from_ocaml

Trying to compile ocaml into javascript. Some OCaml code I have put in https://gist.github.com/larsr/6b3cd6f62d54d56e3f9a uses the menhir parser, and the js_of_ocaml library together. I've installed them with opam. The code comes from…
larsr
  • 5,447
  • 19
  • 38
1
vote
1 answer

Js_of_ocaml - Error when get cookie

I'm XmlHttpRequest in order to make http request and I want to get the cookies. The code to get cookie : let http_post url = XmlHttpRequest.perform_raw_url ~post_args:[("login", `String (Js.string "foo")); ("password", `String…
alifirat
  • 2,899
  • 1
  • 17
  • 33
1
vote
1 answer

How to set an attribute of a Dom element

I have created a td element with a call such as: let td = Dom_html.createTd doc in I would now like to set an attribute on this object. I have…
Lyn Headley
  • 11,368
  • 3
  • 33
  • 35
1
vote
1 answer

How to construct a js object and call its methods with js_of_ocaml?

I try to build an application using js_of_ocaml. Let's say I have the following code in javascript : function MyFunction(){ this.name = "a" } MyFunction.prototype.setName = function(arg){ this.name = arg } How to write in OCaml/js_of_caml a code…
Zooky
  • 133
  • 4