More event system tweaks.
authorTilman Sauerbeck <tilman@code-monkey.de>
Tue, 14 Feb 2006 22:20:14 +0000 (22:20 +0000)
committerTilman Sauerbeck <tilman@code-monkey.de>
Tue, 14 Feb 2006 22:20:14 +0000 (22:20 +0000)
src/ecore/rb_event_handler.c

index 5dabfe73fb939c77e08ade7d784740de923a6bd2..4dd45ce6b35e6567d9ab05735949729583b86647 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * $Id: rb_event_handler.c 365 2006-02-14 21:50:47Z tilman $
+ * $Id: rb_event_handler.c 367 2006-02-14 22:20:14Z 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,11 +186,16 @@ 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;
 }
 
+static VALUE c_ev_init (int argc, VALUE *argv, VALUE self)
+{
+       return self;
+}
+
 VALUE c_ev_inherited_noop (VALUE klass, VALUE child)
 {
        return Qnil;
@@ -192,12 +206,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 +236,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);
 }