From: Takaaki T. <tt...@ja...> - 2001-09-02 14:09:46
|
At Sat, 1 Sep 2001 17:02:39 -0700 (PDT), Kevin Smith wrote: > It seems like we need some kind of general map so we can > invoke various kinds of callbacks from C++. For each > callback, we need to store both the callback proc/block, > and a data value. For widget callbacks, what we have works > fine. > But a client could add ten timer callbacks and ten idle > callbacks, each with different data values. We need some > way to handle those, and whatever that way is might end up > also being usable for widget callbacks (to avoid duplicate > code). > Any ideas on this? Did you mention Fl::add_fd(), Fl::add_idle(), Fl::add_timeout() and so on? I'm going to pass the Array object which contains Proc object and user data to a function, if the function has the parameter for user data. For example: void rb_idle_func(void *data) { VALUE proc = rb_ary_entry((VALUE)data, 0); VALUE user_data = rb_ary_entry((VALUE)data, 1); rb_funcall(proc, rb_intern("call"), 1, user_data); }; VALUE rb_fl_idle(VALUE self, VALUE proc, VALUE user_data) { VALUE pass_data = rb_assoc_new(proc, user_data); Fl::add_idle(rb_idle_func, (void*)pass_data); return Qnil; }; Of course, we must give care to the memory management. -- Takaaki Tateishi <tt...@ja...> |