gen_js_api
gen_js_api copied to clipboard
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)|])