From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail4-relais-sop.national.inria.fr (mail4-relais-sop.national.inria.fr [192.134.164.105]) by walapai.inria.fr (8.13.6/8.13.6) with ESMTP id q43IfZfk005882 for ; Thu, 3 May 2012 20:41:35 +0200 X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AhwBAF/Qok/RVaA2kGdsb2JhbABEsnMIIgEBAQEJCQ0HFAQjggoBAQQSAhMZARsdAQMMBgULOyIBEQEFARwGNYdcAQMLC5wDCQOMJIJzhR4KGScNV4h2AQULkH0ElX6BEY1RPYQM X-IronPort-AV: E=Sophos;i="4.75,526,1330902000"; d="scan'208";a="142485545" Received: from mail-pb0-f54.google.com ([209.85.160.54]) by mail4-smtp-sop.national.inria.fr with ESMTP/TLS/RC4-SHA; 03 May 2012 20:41:29 +0200 Received: by pbbro2 with SMTP id ro2so3662227pbb.27 for ; Thu, 03 May 2012 11:41:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=9EVGtWqPOXRvoVLxms0NYQR07QabdwfLpteEK7lCL1Y=; b=EN2pxTIaC9+RC/kOVo86ocMCYfwQelgx6zPsykoXhKSW0+ayEHchWHy+s9ZtRJg87U fiSKbxKWbw2PFx7K/0fpusy5k9SL/vpBEaXDD0vyZgp4hvBKqzf1zqyJv4NVkTYEy8/D mSMUoJ9DAVzddbCjZzo7KjRqcuHmNN+VW5Tw9UI3z3O+zMstrXSvXyLvHcxyo7mHt5zE WvJlk4hK+2nFFLQ1E7ZrRCKK92e0OrvF3vzkiKEf/xeHturOqjd048QhbFPfuRS4hM9H k9Rryln3GTWs/xoG/tHZ3ohwBzuQ1ui3Qe3l13Cn8E4/x9JmDljS4l9HJY/2r2G7Q5ER LUdw== MIME-Version: 1.0 Received: by 10.68.239.73 with SMTP id vq9mr5463618pbc.94.1336070487264; Thu, 03 May 2012 11:41:27 -0700 (PDT) Received: by 10.68.228.194 with HTTP; Thu, 3 May 2012 11:41:27 -0700 (PDT) In-Reply-To: References: <871un1z8sq.fsf@frosties.localnet> Date: Thu, 3 May 2012 19:41:27 +0100 Message-ID: From: Joel Reymont To: Gabriel Scherer Cc: Goswin von Brederlow , caml-list@inria.fr Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [Caml-list] using modules to wrap c++ classes So I ended up with something like this --- Callbacks.ml type t type 'a callback = | Alert of ('a -> Alert.t -> unit) | AskQuote of ('a -> Ask.t -> unit) | BestAskQuote of ('a -> Ask.t -> unit) | BidQuote of ('a -> Bid.t -> unit) | BestBidQuote of ('a -> Bid.t -> unit) | ClosePrice of ('a -> ClosePrice.t -> unit) | ClosingIndicator of ('a -> ClosingIndicator.t -> unit) | EndQuote of of ('a -> EndQuote.t -> unit) | EquityOptionList of of ('a -> EquityOptionList.t -> unit) | EquityOptionStrategyList of of ('a -> EquityOptionStrategyList.t -> unit) | HighPrice of ('a -> HighPrice.t -> unit) | Indicator of ('a -> Indicator.t -> unit) | IndicatorReplay of ('a -> IndicatorReplay.t -> unit) | LimitOrderBook of ('a -> LimitOrderBook.t -> unit) | LowPrice of ('a -> LowPrice.t -> unit) | MarketMode of ('a -> MarketMode.t -> unit) | OpenPrice of ('a -> OpenPrice.t -> unit) ... external make : unit -> t = "Callbacks_new" external set : t -> 'a callback -> unit = "Callbacks_set" I now want to grab the closure from the constructor on the C side and stick it into a callback array. Is this sufficient? extern "C" CAMLprim value Callbacks_set(value v) { CAMLparam1(v); int i = Tag_val(v); CAMLlocal1(f); f = Field(0, v); caml_register_global_root(f); callbacks[i] = f; CAMLreturn(Val_unit); } Thanks, Joel -------------------------------------------------------------------------- Working on AlgoKit, a new algorithmic trading platform using Rithmic R|API ---------------------+------------+--------------------------------------- http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont ---------------------+------------+---------------------------------------