package gen_js_api
Install
Dune Dependency
Authors
Maintainers
Sources
md5=efe14f394576c5bb60ae0d53fb402ca8
sha512=cda932339a16c85888b4d410fa18d1e179cd66eb0e39a611e545aac5583f9bb76c0325977dd7d9cf0ac40ad10ec0e5879a8a748ac6e045b469cddd9d8097a176
Description
gen_js_api aims at simplifying the creation of OCaml bindings for Javascript libraries. Authors of bindings write OCaml signatures for Javascript libraries and the tool generates the actual binding code with a combination of implicit conventions and explicit annotations.
gen_js_api is to be used with the js_of_ocaml compiler.
Published: 26 May 2020
README
gen_js_api: easy OCaml bindings for Javascript libraries
Overview
gen_js_api aims at simplifying the creation of OCaml bindings for Javascript libraries. It must currently be used with the js_of_ocaml compiler, although other ways to run OCaml code "against" Javascript might be supported later with the same binding definitions (for instance, Bucklescript, or direct embedding of a JS engine in a native OCaml application).
gen_js_api is based on the following ideas:
- Authors of bindings write OCaml signatures for Javascript libraries and the tool generates the actual binding code with a combination of implicit conventions and explicit annotations.
- The generated binding code takes care of translating values between OCaml and Javascript and of dealing with Javascript calling conventions.
- All syntactic processing is done by authors of bindings: the client code is normal OCaml code and does not depend on custom syntax nor on JS-specific types.
gen_js_api can be used in two complementary ways:
- Generating .ml implementations from annotated .mli interfaces, in order to create the code for stub libraries.
- As a ppx preprocessor on implementations to define local bindings.
Examples
The repository contains some examples of OCaml bindings to Javascript libraries created with gen_js_api:
- Very partial bindings to jQuery, with some example client code.
- Partial bindings to Javascript strings and regexps and Javascript dates.
- Some ad hoc test to exercise various features.
- An example of a self-contained program, a simple calculator, implementing local .bindings
Documentation
- Install and use
- Low-level binding to Javascript
- Using gen_js_api to generate .ml from .mli
- Using gen_js_api as a ppx processor
- Default naming convention
- JS-able types and type declarations
- Value bindings
- Class-wrapping bindings
- TODO list
Related projects
- js_of_ocaml: The compiler and runtime system on which gen_js_api relies. (Note: gen_js_api doesn't depend on js_of_ocaml's OCaml library, nor on its language extension.)
- goji: A DSL to describe OCaml bindings for JavaScript libraries.
- DefinitelyMaybeTyped: A project to parse DefinitelyTyped interfaces and produce OCaml interfaces.
- Bucklescript: Another compiler from OCaml to Javascript.
About
gen_js_api has been created by LexiFi for porting a web application from Javascript to OCaml. The tool has been used in production since 2015.
This gen_js_api package is licensed by LexiFi under the terms of the MIT license.
See see Changelog
Contact: alain.frisch@lexifi.com
Contributors:
- Alain Frisch
- Sebastien Briais
Dependencies (7)
-
ppxlib
>= "0.36"
-
ocaml
< "5.3"
-
ppxlib
>= "0.11" & < "0.36"
-
ocaml-migrate-parsetree
>= "1.6.0" & < "2.0.0"
-
js_of_ocaml
>= "3.1.0"
-
dune
>= "1.11"
-
ocaml
>= "4.08.0"
Dev Dependencies
None
Used by (44)
- cordova
- cordova-plugin-activity-indicator
- cordova-plugin-background-mode
- cordova-plugin-barcode-scanner
- cordova-plugin-battery-status
- cordova-plugin-camera
- cordova-plugin-clipboard
- cordova-plugin-datepicker
- cordova-plugin-device
- cordova-plugin-device-motion
- cordova-plugin-device-orientation
- cordova-plugin-dialogs
- cordova-plugin-email-composer
- cordova-plugin-fcm
- cordova-plugin-file
- cordova-plugin-file-opener
- cordova-plugin-file-transfer
- cordova-plugin-geolocation
- cordova-plugin-globalization
- cordova-plugin-image-picker
- cordova-plugin-inappbrowser
- cordova-plugin-insomnia
- cordova-plugin-keyboard
- cordova-plugin-loading-spinner
- cordova-plugin-local-notifications
- cordova-plugin-media
- cordova-plugin-media-capture
- cordova-plugin-network-information
- cordova-plugin-progress
- cordova-plugin-push-notifications
- cordova-plugin-qrscanner
- cordova-plugin-screen-orientation
- cordova-plugin-sim-card
- cordova-plugin-sms
- cordova-plugin-social-sharing
- cordova-plugin-statusbar
- cordova-plugin-toast
- cordova-plugin-touch-id
- cordova-plugin-vibration
- cordova-plugin-videoplayer
-
jsonoo
< "0.3.0"
- ocaml-js-stdlib
-
ocaml-vdom
< "transition"
-
promise_jsoo
< "0.4.2"
Conflicts
None