I am a beginner at both Javascript and js_of_ocaml
, so I may be mixing up all sorts of mistakes and misconceptions here.
I have compiled up an existing project, my command line PDF tools, using js_of_ocaml
, and all is well:
$ node cpdf.js -info hello.pdf
Encryption: Not encrypted
Permissions:
Linearized: false
Version: 1.1
Pages: 1
Like magic! But I had to comment out the parts of my code which use external C code of course - that is zlib and some encryption primitives. So now I wish to bind javascript libraries for those. I am experimenting with a simple library of my own, first, which is given on the command line to js_of_ocaml
as foomod.js
:
foo = 42;
I can get to this global variable easily from OCaml:
let foo = Js.Unsafe.global##.foo
But now I want to do things better, and I change foomod.js
to:
exports.foo = 42;
How can I get to that? Giving foomod.js
on the js_of_ocaml
command line includes the contents of foomod.js
in some way, but does not contain the string foomod
, so I’m not sure how to get to the foomod’s variables and functions. How to I access them? In the node REPL, I can simply do:
> foomod = require('./foomod.js');
{ foo; 42 }
> foomod.foo;
42
I have read the js_of_ocaml
help page on how to bind JS modules:
https://ocsigen.org/js_of_ocaml/latest/manual/bindings
I imagine if I could get over this hump, all the rest of the information I need will be there.