From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail2-relais-roc.national.inria.fr (mail2-relais-roc.national.inria.fr [192.134.164.83]) by sympa.inria.fr (Postfix) with ESMTPS id 7C0487FCCB for ; Thu, 30 Apr 2015 00:49:06 +0200 (CEST) Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of mfp@acm.org) identity=pra; client-ip=86.109.99.132; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="ferferse@telefonica.net"; x-sender="mfp@acm.org"; x-conformance=sidf_compatible Received-SPF: Pass (mail2-smtp-roc.national.inria.fr: domain of ferferse@telefonica.net designates 86.109.99.132 as permitted sender) identity=mailfrom; client-ip=86.109.99.132; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="ferferse@telefonica.net"; x-sender="ferferse@telefonica.net"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail2-smtp-roc.national.inria.fr: no sender authenticity information available from domain of postmaster@smtp.movistar.es) identity=helo; client-ip=86.109.99.132; receiver=mail2-smtp-roc.national.inria.fr; envelope-from="ferferse@telefonica.net"; x-sender="postmaster@smtp.movistar.es"; x-conformance=sidf_compatible X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: A0DLAQA7X0FVcoRjbVZcg19ctBQBAQEBBpFtgVOGBIICEgEBAQEBAQERAQoNCQkREC6EIQEFJwsBVgsYCSUPBSghAYhBCcgIhhaFIoRSg1GBFgEElXOGPoEkhgowhFKJSYIqHIFTbYJFAQEB X-IPAS-Result: A0DLAQA7X0FVcoRjbVZcg19ctBQBAQEBBpFtgVOGBIICEgEBAQEBAQERAQoNCQkREC6EIQEFJwsBVgsYCSUPBSghAYhBCcgIhhaFIoRSg1GBFgEElXOGPoEkhgowhFKJSYIqHIFTbYJFAQEB X-IronPort-AV: E=Sophos;i="5.11,672,1422918000"; d="scan'208";a="138198043" Received: from smtp08.acens.net (HELO smtp.movistar.es) ([86.109.99.132]) by mail2-smtp-roc.national.inria.fr with ESMTP; 30 Apr 2015 00:49:05 +0200 X-CTCH-RefID: str=0001.0A0B0203.55415FDF.01A2,ss=1,re=0.000,recu=0.000,reip=0.000,cl=1,cld=1,fgs=0 X-CTCH-Spam: Unknown Received: from AIKA (81.34.230.108) by smtp.movistar.es (8.6.122.03) (authenticated as ferferse$telefonica.net) id 551313FF013CEE01; Wed, 29 Apr 2015 22:49:03 +0000 Received: from mfp by AIKA with local (Exim 4.80) (envelope-from ) id 1Ynamt-0002fL-3X; Thu, 30 Apr 2015 00:49:03 +0200 Date: Thu, 30 Apr 2015 00:49:02 +0200 From: Mauricio =?iso-8859-1?Q?Fern=E1ndez?= To: Helmut Brandl , caml-list@inria.fr Message-ID: <20150429224902.GA8181@AIKA> Mail-Followup-To: Helmut Brandl , caml-list@inria.fr References: <553E9CD0.5040203@gmx.net> <553EB228.9080801@frisch.fr> <0AF7BAC7BE62417CB13C1B30392B80CC@erratique.ch> <553F3C86.4060809@frisch.fr> <553F6C57.50407@zoho.com> <55415529.2010802@gmx.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <55415529.2010802@gmx.net> User-Agent: Mutt/1.5.21 (2010-09-15) Subject: Re: [Caml-list] js_of_ocaml with node On Wed, Apr 29, 2015 at 05:03:21PM -0500, Helmut Brandl wrote: > Thanks to all for the hints. > > I think I have to dig into the documentation of js_of_ocaml to > resolve the problem. I've got some bindings for nodejs stuff including FS operations, sockets, events, processes, etc.; will try to publish it tomorrow. Note that some nodejs functions require variadic callbacks as supported by the patches available at https://github.com/ocsigen/js_of_ocaml/issues/273 The hand-written bindings look like this (just a sneak peek): node_require.eliom: {client{ let require x = let require = Js.Unsafe.eval_string "require" in require##call(require, Js.string x) }} (* vim: set ft=ocaml: *) node_fs.eliom: {client{ open Printf open Lwt class type error = object method message : Js.js_string Js.t Js.prop end type maybe_error = error Js.t Js.opt class type stats = object method dev : int Js.readonly_prop method ino : int Js.readonly_prop method mode : int Js.readonly_prop method nlink : int Js.readonly_prop method uid : int Js.readonly_prop method gid : int Js.readonly_prop method rdev : int Js.readonly_prop method size : float Js.t Js.readonly_prop method blksize : int Js.readonly_prop method blocks : int Js.readonly_prop method atime : Js.date Js.t Js.readonly_prop method mtime : Js.date Js.t Js.readonly_prop method ctime : Js.date Js.t Js.readonly_prop end and watch_options = object method persistent : bool Js.t Js.prop end class type fs = object method existsSync : Js.js_string Js.t -> bool Js.t Js.meth method exists : Js.js_string Js.t -> (bool Js.t -> unit) Js.callback -> unit Js.meth method readFile : Js.js_string Js.t -> (maybe_error -> Node_net.buffer Js.t -> unit) Js.callback -> unit Js.meth method readFileSync : Js.js_string Js.t -> Node_net.buffer Js.t Js.meth method readdirSync : Js.js_string Js.t -> Js.js_string Js.t Js.js_array Js.t Js.meth method statSync : Js.js_string Js.t -> stats Js.t Js.opt Js.meth method lstatSync : Js.js_string Js.t -> stats Js.t Js.opt Js.meth method mkdir : Js.js_string Js.t -> int -> (maybe_error -> unit) Js.callback -> unit Js.meth method mkdirSync : Js.js_string Js.t -> int -> unit Js.meth method unlink : Js.js_string Js.t -> (maybe_error -> unit) Js.callback -> unit Js.meth method unlinkSync : Js.js_string Js.t -> unit Js.meth method watch : 'a. Js.js_string Js.t -> (#watch_options as 'a) Js.t -> (Js.js_string -> Js.js_string -> unit) Js.callback -> unit Js.meth end let fs : fs Js.t = Node_require.require "fs" let err_callback1 u err = match Js.Opt.to_option err with None -> Lwt.wakeup_later u () | Some err -> Lwt.wakeup_later_exn u (Failure (Js.to_string err##message)) let bool_callback1 u b = Lwt.wakeup_later u (Js.to_bool b) let wrap_async1 callback f = let t, u = Lwt.wait () in f (Js.wrap_callback (callback u)); t let exists s = wrap_async1 bool_callback1 (fun cb -> fs##exists(Js.string s, cb)) let unlink s = wrap_async1 err_callback1 (fun cb -> fs##unlink(Js.string s, cb)) let read_file fname = let t, u = Lwt.wait () in let on_read err data = if Js.Opt.test err then Lwt.wakeup_later_exn u (Failure (sprintf "could not read %S" fname)) else Lwt.wakeup_later u (Js.to_string data##toString()) in fs##readFile(Js.string fname, Js.wrap_callback on_read); t }} (* vim: set ft=ocaml: *) -- Mauricio Fernández