>>>>> "A" == Arno Erpenbeck <aerpenbe / uos.de> writes:

A> is it possible to supply Proc arguments to a constructor of
A> a class in a C extension so that it keeps these references for later
A> usage?

 Store it in a struct, or use instance variables.

A> static VALUE Foo_new(VALUE class, VALUE proc1, VALUE proc2) {
A>  // do what?
A> }

 Something like this : *pseudo-code* and *not* tested

 struct tt {
   VALUE p1, p2;
 }

 static VALUE tt_mark(struct tt *tt_st)
 {
    rb_gc_mark(tt_st->p1);
    rb_gc_mark(tt_st->p2);
 }

 static VALUE Foo_new(VALUE klass, VALUE proc1, VALUE proc2)
 {
    struct tt *tt_st;
    VALUE res = Data_Make_Struct(klass, struct tt, tt_mark, free, tt_st);
    tt_st->p1 = proc1;
    tt_st->p2 = proc2;
    {
       VALUE tmp[2];
       tmp[0] = proc1;
       tmp[1] = proc2;
       rb_obj_call_init(res, 2, tmp);
    }
    return res;
  }

  static VALUE tt_bar(VALUE obj)
  {
     struct tt *tt_st;
     VALUE res = rb_ary_new();
     Data_Get_Struct(obj, struct tt, tt_st);
     rb_ary_push(res, rb_funcall2(tt_st->p1, rb_intern("call"), 0, 0));
     rb_ary_push(res, rb_funcall2(tt_st->p2, rb_intern("call"), 0, 0));
     return res;
  }

     

Guy Decoux