Say I have a library class AdmCallbacks class AdmCallbacks { public : AdmCallbacks(); virtual ~AdmCallbacks();
/* ---------------------------------------------------------------- */ virtual int Alert(AlertInfo * pInfo, void * pContext, int * aiCode) = 0; private : }; I subclass it and implement the Alert method to receive notifications. I then create an instance of my derived class and pass it to some initialization function so that the API knows to call the methods of my instance. My derived class may look like this class MyAdmCallbacks: public AdmCallbacks { public : MyAdmCallbacks() {}; ~MyAdmCallbacks() {}; /* ---------------------------------------------------------------- */ virtual int Alert(AlertInfo * pInfo, void * pContext, int * aiCode); }; int MyAdmCallbacks::Alert(AlertInfo * pInfo, void * pContext, int * aiCode) { int iIgnored; /* ---------------------------------------------------------------- */ cout << endl << endl; if (!pInfo -> dump(&iIgnored)) { cout << "error in pInfo -> dump : " << iIgnored << endl; } /* ---------------------------------------------------------------- */ *aiCode = API_OK; return (OK); } Now, suppose I want to implement the derived class on the OCaml side. What is the best way to do it? I can derive on the C++ side, keep a pointer to the OCaml instance (self) in a member variable, instantiate MyAdmCallbacks in the "MyAdmCallbacks_new" stub function which takes the OCaml self and then set the member variable. The Alert method on the C++ side would then dispatch to OCaml using the stored OCaml self to call the Alert method as per 18.3.5 of the manual callback(caml_get_public_method(foo, hash_variant("bar")), foo); Is there a better way to implement this on the OCaml side? Thanks, Joel -------------------------------------------------------------------------- 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