caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Joel Reymont <joelr1@gmail.com>
To: Goswin von Brederlow <goswin-v-b@web.de>
Cc: Gabriel Scherer <gabriel.scherer@gmail.com>, caml-list@inria.fr
Subject: Re: [Caml-list] using modules to wrap c++ classes
Date: Fri, 4 May 2012 18:23:47 +0100	[thread overview]
Message-ID: <CAOQwdX1PUPz3E76c9QcOf61Ak4c5+83ANYvM21jA9dQ_6RyvnA@mail.gmail.com> (raw)
In-Reply-To: <8762ccqqt0.fsf@frosties.localnet>

On Fri, May 4, 2012 at 9:43 AM, Goswin von Brederlow <goswin-v-b@web.de> wrote:

> As discussed on irc you need to create your callbacks[] array as ocaml
> block and register that itself as root. That also has the benefit that
> you only have to register a single root instead of 50.

Assuming that I have a class named MyCallbacks with a public member
callbacks of type value, is this correct?

Also, can I use Is_block to check if there's a closure value stored in
the callbacks block before I dispatch to the closure?

    Thanks, Joel

---

// finalizer, stored in custom_operations

void Callbacks_delete(value v)
{
  CAMLparam1(v);
  MyCallbacks* o = Callbacks_val(v);
  caml_remove_global_root(&o->callbacks);
  delete o;
}

CAMLprim value
Callbacks_new()
{
  CAMLparam0();
  CAMLlocal2(v, cbks);
  v = caml_alloc_custom(&ops, sizeof(MyCallbacks*), 0, 1);
  MyCallbacks* o = new MyCallbacks();
  Callbacks_val(v) = o;
  cbks = caml_alloc(NUM_CBKS, 0);
  o->callbacks = cbks;
  caml_register_global_root(&o->callbacks);
  CAMLreturn(v);
}

extern "C" CAMLprim value
Callbacks_set(value self, value cbk)
{
  CAMLparam2(self, cbk);
  MyCallbacks* o = Callbacks_val(self);
  Store_field(o->callbacks, Tag_val(cbk), Field(0, cbk));
  CAMLreturn(Val_unit);
}

--------------------------------------------------------------------------
Working on AlgoKit, a new algorithmic trading platform using Rithmic R|API
---------------------+------------+---------------------------------------
http://wagerlabs.com | @wagerlabs | http://www.linkedin.com/in/joelreymont
---------------------+------------+---------------------------------------

  reply	other threads:[~2012-05-04 17:24 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
2012-05-03 19:20           ` Joel Reymont
2012-05-04  8:43           ` Goswin von Brederlow
2012-05-04 17:23             ` Joel Reymont [this message]
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=CAOQwdX1PUPz3E76c9QcOf61Ak4c5+83ANYvM21jA9dQ_6RyvnA@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;
as well as URLs for NNTP newsgroup(s).