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
.