Open jetjinser opened 3 months ago
Yes, env
is just a (polymorphic) record, so you can create your own with whatever fields you want:
let env =
object
method cwd = ...
end
in
...
For example, here is Eio_mock.Backend
creating a mock environment: https://github.com/ocaml-multicore/eio/blob/33d4e01a30aae0ae55747e29c1fc4ea6e741571b/lib_eio/mock/backend.ml#L55-L60
Note that libraries don't normally use eio_main
(only the application should use that).
Thanks!
Note that libraries don't normally use eio_main (only the application should use that).
Yes, you are right, I was wrong. The part using eio_main is an application. In fact, it is a project including bin and lib, and the lib part uses Eio_main.Stdenv.base
.
Another thing I want to ask is, the reason why the env of Eio_js_backend.start
is unit is that the compiled JavaScript may be used in the browser or node/bun/anything, and the api of each is different?
Should this be provided by some kind of eio_node_backend
?
Another thing I want to ask is, the reason why the env of Eio_js_backend.start is unit is that the compiled JavaScript may be used in the browser or node/bun/anything, and the api of each is different? Should this be provided by some kind of eio_node_backend?
I don't know (I didn't write eio_js
), but that sounds like a reasonable thing to do.
I've just started using OCaml and eio, and what I'm working on is making a library that uses eio_main be compiled into JavaScript that is nodejs callable via jsoo.
As far as I understand, functions in Eio.Stdenv will only access the capabilities in
env
that they need. Does this mean that only part of theenv
need to be implemented?For example, in nodejs, there is the fs api, so is it possible to make functions like
Eio.Stdenv.cwd
work?Another little question is, if I want to construct an
env
myself, is it difficult? How can I do it?