とくに新出のトランスパイラだと、バインディングが少ないので、いかにしてFFI叩くかが勝負になる
参考: https://bloomberg.github.io/bucklescript/Manual.html
main.re
let add a b => a + b;
Js.log "this is console.log";
Js.log(add 3 4);
/* function call */
external imul : int => int => int = "Math.imul" [@@bs.val];
Js.log(imul 3 4);
/* function call with unit */
external now : unit => int = "Date.now" [@@bs.val];
Js.log(now());
/* new */
external create_date: unit => string = "Date" [@@bs.new];
Js.log(create_date());
/* value */
external dirname : string = "__dirname" [@@bs.val];
Js.log dirname;
/* require */
external resolve_path : string => string => string = "resolve" [@@bs.val] [@@bs.module "path"];
Js.log(resolve_path "a" "b");
コンパイル後
// Generated by BUCKLESCRIPT VERSION 1.5.2, PLEASE EDIT WITH CARE
'use strict';
var Path = require("path");
function add(a, b) {
return a + b | 0;
}
console.log("this is console.log");
console.log(7);
console.log(Math.imul(3, 4));
console.log(Date.now());
console.log(new Date());
console.log(__dirname);
console.log(Path.resolve("a", "b"));
exports.add = add;
/* Not a pure module */