2

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 () =
  let oneArgument (a: int) = a + 100 in
  Js.Unsafe.global##.jsOneArgument := Js.wrap_callback oneArgument;
  print_string "hello\n";
  exit 0

The following 2 commands generate a bytecode T, and translates T to cubes.js:

ocamlfind ocamlc -package js_of_ocaml.ppx -linkpkg cubes.ml -o T

js_of_ocaml T -o cubes.js

I have tested that the function jsOneArgument of cubes.js can well be called by other JS or HTML files. So my 1) goal is satisfied.

However, my 2) goal cannot be satisfied: ./T returns an error:

:testweb $ ./T
Unimplemented Javascript primitive caml_pure_js_expr!

Although node cubes.js returns hello, I do need to be able to test ./T directly, because when there is an error, it would show well the error position, whereas the information shown by node cubes.js is not readable...

So does anyone know how to solve that?

PS: node --version gives v6.1.0; npm --version gives 3.8.6; ocaml -version gives The OCaml toplevel, version 4.02.3. js_of_ocaml --version gives 2.7.

3
  • ./T is javascript, you need node to run it. You can make the process easier by using --custom-header of js_of_ocaml, aka --custom-header='/usr/bin/env node' Commented May 19, 2016 at 22:12
  • Where should i put this --custom-header='/usr/bin/env node'? Commented May 20, 2016 at 16:19
  • its mentioned in the man page of js_of_ocaml, recommend reading the man page of the tools you use. Commented May 23, 2016 at 21:40

1 Answer 1

4

I don't see anyway to avoid the use of node but you can improve the information returned by it by

  1. compiling the OCaml with the debug info (add -g option to ocamlc)

  2. add the options --debuginfo --sourcemap --pretty to the invocation of js_of_ocaml

In your example, you'd have to do

ocamlfind ocamlc -g -package js_of_ocaml.ppx -linkpkg cubes.ml -o T
js_of_ocaml --debuginfo --sourcemap --pretty T -o cubes.js
Sign up to request clarification or add additional context in comments.

1 Comment

./T still returns Unimplemented Javascript primitive caml_pure_js_expr!.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.