Support for primitives bindings
Description
This PR adds support for a new attribute [@js.runtime "string"] that allows bindings a js_of_ocaml pritimitive using Jsoo_runtime.Sys.external_ from https://github.com/ocsigen/js_of_ocaml/pull/2086
For instance:
val path: Ojs.t [@@js.runtime "node_path"]
expands to
let (path : Ojs.t) = Jsoo_runtime.Sys.external_ "node_path"
I also added an extension of the existing "js.scope" attribute by adding an "@" to the parameter you can refer to a runtime primitive.
Example:
[@@@js.scope "@node_fs.promises"]
...
val unlink: string -> unit Promise.t [@@js.global]
expands to
let (unlink : string -> unit Promise.t) =
fun (x50 : string) ->
Promise.t_of_js Ojs.unit_of_js
(Ojs.call
(Ojs.get_prop_ascii (Jsoo_runtime.Sys.external_ "node_fs")
"promises") "unlink" [|(Ojs.string_to_js x50)|])
I've tried to update the PR with the latest change from jsoo https://github.com/ocsigen/js_of_ocaml/pull/2086 (see branch https://github.com/hhugo/gen_js_api/tree/runtime-primitives-bindings-hh). I've also tried to check that it works fine with wasmoo, but tests fail because of boxed floats I guess. @vouillon, would you be able to fix the gen_js_api tests for wasmoo ?
This new feature needs to be documented
@vouillon, would you be able to fix the gen_js_api tests for wasmoo ?
I think you just need to replace the occurrences of "123" by (Ojs.string_to_js "123").
@hhugo I cherry-picked your branch, adapted the PR and document the new features, I'll wait https://github.com/ocsigen/js_of_ocaml/pull/2086 to merge this and make a new release of gen_js_api.
@hhugo I cherry-picked your branch, adapted the PR and document the new features, I'll wait ocsigen/js_of_ocaml#2086 to merge this and make a new release of gen_js_api.
ocsigen/js_of_ocaml#2086 has been merged ! @hhugo: can we expect a release of JSOO soon?
Gentle reminder
Gentle ping
Bump
@smorimoto thanks for the ping. Now that js_of_ocaml has had a release, this one can go forward. We'll try to merge & cut a release shortly.