On Fri, May 4, 2012 at 9:43 AM, Goswin von Brederlow <goswin-...@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 ---------------------+------------+--------------------------------------- -- Caml-list mailing list. Subscription management and archives: https://sympa-roc.inria.fr/wws/info/caml-list Beginner's list: http://groups.yahoo.com/group/ocaml_beginners Bug reports: http://caml.inria.fr/bin/caml-bugs