/*
- * $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)
*
} 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;
/* 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;
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;
/* 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;
}
/* 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);
}