X-Git-Url: http://git.code-monkey.de/?a=blobdiff_plain;f=src%2Fecore%2Frb_event_handler.c;h=18e2fc7fc5a0562576da4a2dbe9ef8c45d528d05;hb=6c769aac08caf234bbff82cca822d8f209283bbe;hp=5dabfe73fb939c77e08ade7d784740de923a6bd2;hpb=4f2835571a13e31777b36def3056547b997e0599;p=ruby-ecore.git diff --git a/src/ecore/rb_event_handler.c b/src/ecore/rb_event_handler.c index 5dabfe7..18e2fc7 100644 --- a/src/ecore/rb_event_handler.c +++ b/src/ecore/rb_event_handler.c @@ -1,5 +1,5 @@ /* - * $Id: rb_event_handler.c 365 2006-02-14 21:50:47Z tilman $ + * $Id: rb_event_handler.c 372 2006-02-16 20:39:55Z tilman $ * * Copyright (C) 2004 ruby-ecore team (see AUTHORS) * @@ -35,7 +35,7 @@ typedef struct { } RbEventHandler; static int on_ecore_event (void *data, int type, void *event); -static VALUE c_ev_raise (VALUE klass, VALUE event); +static VALUE c_ev_raise (VALUE klass, VALUE argv); VALUE event_classes, cEcoreEvent; static VALUE handlers; @@ -145,7 +145,16 @@ static int on_ecore_event (void *data, int type, void *event) /* now create and init the object */ tmp = (VALUE) event; - obj = rb_class_new_instance (1, &tmp, klass); + + /* if tmp is a Ruby class, we'll just pass the arguments to the + * initialize method. + * if it's a c struct, we can use rb_class_new_instance() + */ + if (rb_respond_to (klass, rb_intern ("raise"))) { + obj = rb_obj_alloc (klass); + rb_apply (obj, rb_intern ("initialize"), tmp); + } else + obj = rb_class_new_instance (1, &tmp, klass); len = RARRAY (handlers)->len; @@ -177,14 +186,14 @@ VALUE c_ev_inherited (VALUE klass, VALUE child) rb_hash_aset (event_classes, t, child); rb_define_const (child, "TYPE", t); - rb_define_singleton_method (child, "raise", c_ev_raise, 1); + rb_define_singleton_method (child, "raise", c_ev_raise, -2); return Qnil; } -VALUE c_ev_inherited_noop (VALUE klass, VALUE child) +static VALUE c_ev_init (int argc, VALUE *argv, VALUE self) { - return Qnil; + return self; } static void free_ruby_event (void *data, void *event) @@ -192,12 +201,12 @@ static void free_ruby_event (void *data, void *event) /* do nothing */ } -static VALUE c_ev_raise (VALUE klass, VALUE event) +static VALUE c_ev_raise (VALUE klass, VALUE argv) { VALUE t; t = rb_const_get (klass, rb_intern ("TYPE")); - ecore_event_add (FIX2INT (t), (void *) event, free_ruby_event, NULL); + ecore_event_add (FIX2INT (t), (void *) argv, free_ruby_event, NULL); return Qnil; } @@ -222,4 +231,5 @@ void Init_EventHandler (void) /* define a base event class */ cEcoreEvent = rb_define_class_under (mEcore, "Event", rb_cObject); rb_define_singleton_method (cEcoreEvent, "inherited", c_ev_inherited, 1); + rb_define_method (cEcoreEvent, "initialize", c_ev_init, -1); }