From: Joel Reymont <joelr1@gmail.com>
To: Gabriel Scherer <gabriel.scherer@gmail.com>
Cc: Goswin von Brederlow <goswin-v-b@web.de>, caml-list@inria.fr
Subject: Re: [Caml-list] using modules to wrap c++ classes
Date: Thu, 3 May 2012 19:41:27 +0100 [thread overview]
Message-ID: <CAOQwdX0Hap02NZMW53Mx-bUiP3tOUZPH6tUYQv7fWY3EdSjdcQ@mail.gmail.com> (raw)
In-Reply-To: <CAOQwdX3EXJ7fCrtMMTrnExaBMMTagDz_7ycv_JYe5SUHfv4scw@mail.gmail.com>
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
---------------------+------------+---------------------------------------
next prev parent reply other threads:[~2012-05-03 18:41 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-05-03 12:22 Joel Reymont
2012-05-03 13:35 ` Goswin von Brederlow
2012-05-03 13:56 ` Joel Reymont
2012-05-03 14:27 ` Gabriel Scherer
2012-05-03 15:02 ` Joel Reymont
2012-05-03 18:41 ` Joel Reymont [this message]
2012-05-03 19:20 ` Joel Reymont
2012-05-04 8:43 ` Goswin von Brederlow
2012-05-04 17:23 ` Joel Reymont
2012-05-05 12:39 ` Goswin von Brederlow
2012-05-05 14:11 ` Joel Reymont
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAOQwdX0Hap02NZMW53Mx-bUiP3tOUZPH6tUYQv7fWY3EdSjdcQ@mail.gmail.com \
--to=joelr1@gmail.com \
--cc=caml-list@inria.fr \
--cc=gabriel.scherer@gmail.com \
--cc=goswin-v-b@web.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox